Skip to content

Commit 93ae8c3

Browse files
aster-voidclaude
andcommitted
treewide: migrate database from SQLite to PostgreSQL
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1a3e9c8 commit 93ae8c3

File tree

15 files changed

+442
-1239
lines changed

15 files changed

+442
-1239
lines changed

.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# refer to ./src/lib/env/env.server.ts for up-to-date schema
2-
DATABASE_URL="file:local.db"
2+
DATABASE_URL="postgresql://localhost/cms"
33

44
BETTER_AUTH_URL="http://localhost:5173"
55
BETTER_AUTH_SECRET="x0jT5lJCdyNXB32zGQ24VxlFzavHGZeiwplAIyHf6gM="

bun.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

devenv.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{pkgs, ...}: {
2-
packages = [pkgs.sqlite];
2+
packages = [pkgs.postgresql];
33

44
languages.javascript = {
55
enable = true;
@@ -19,6 +19,12 @@
1919
};
2020
};
2121

22+
services.postgres = {
23+
enable = true;
24+
initialDatabases = [{name = "cms";}];
25+
listen_addresses = "127.0.0.1";
26+
};
27+
2228
services.minio = {
2329
enable = true;
2430
buckets = ["dev"];

drizzle.config.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { defineConfig } from "drizzle-kit";
22
import { env } from "./src/lib/env/env.server.ts";
33

4-
const isLocal = env.DATABASE_URL.startsWith("file:");
5-
64
export default defineConfig({
75
schema: "./src/lib/shared/models/schema.ts",
8-
dialect: isLocal ? "sqlite" : "turso",
9-
dbCredentials: isLocal
10-
? { url: env.DATABASE_URL }
11-
: { url: env.DATABASE_URL, authToken: env.DATABASE_AUTH_TOKEN },
6+
dialect: "postgresql",
7+
dbCredentials: { url: env.DATABASE_URL },
128
verbose: true,
139
strict: true,
1410
});
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
CREATE TABLE "account" (
2+
"id" text PRIMARY KEY NOT NULL,
3+
"account_id" text NOT NULL,
4+
"provider_id" text NOT NULL,
5+
"user_id" text NOT NULL,
6+
"access_token" text,
7+
"refresh_token" text,
8+
"id_token" text,
9+
"access_token_expires_at" timestamp with time zone,
10+
"refresh_token_expires_at" timestamp with time zone,
11+
"scope" text,
12+
"password" text,
13+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
14+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
15+
);
16+
--> statement-breakpoint
17+
CREATE TABLE "article" (
18+
"id" text PRIMARY KEY NOT NULL,
19+
"slug" text NOT NULL,
20+
"title" text NOT NULL,
21+
"content" text NOT NULL,
22+
"excerpt" text,
23+
"cover_url" text,
24+
"author_id" text,
25+
"published" boolean DEFAULT false NOT NULL,
26+
"published_at" timestamp with time zone,
27+
"view_count" integer DEFAULT 0 NOT NULL,
28+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
29+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
30+
CONSTRAINT "article_slug_unique" UNIQUE("slug")
31+
);
32+
--> statement-breakpoint
33+
CREATE TABLE "member" (
34+
"id" text PRIMARY KEY NOT NULL,
35+
"user_id" text,
36+
"slug" text NOT NULL,
37+
"name" text NOT NULL,
38+
"bio" text,
39+
"image_url" text,
40+
"page_content" text,
41+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
42+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
43+
CONSTRAINT "member_user_id_unique" UNIQUE("user_id"),
44+
CONSTRAINT "member_slug_unique" UNIQUE("slug")
45+
);
46+
--> statement-breakpoint
47+
CREATE TABLE "project" (
48+
"id" text PRIMARY KEY NOT NULL,
49+
"slug" text NOT NULL,
50+
"name" text NOT NULL,
51+
"description" text,
52+
"content" text,
53+
"cover_url" text,
54+
"repo_url" text,
55+
"demo_url" text,
56+
"category" text DEFAULT 'active' NOT NULL,
57+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
58+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
59+
CONSTRAINT "project_slug_unique" UNIQUE("slug")
60+
);
61+
--> statement-breakpoint
62+
CREATE TABLE "project_member" (
63+
"project_id" text NOT NULL,
64+
"member_id" text NOT NULL,
65+
"role" text DEFAULT 'member' NOT NULL
66+
);
67+
--> statement-breakpoint
68+
CREATE TABLE "session" (
69+
"id" text PRIMARY KEY NOT NULL,
70+
"expires_at" timestamp with time zone NOT NULL,
71+
"token" text NOT NULL,
72+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
73+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
74+
"ip_address" text,
75+
"user_agent" text,
76+
"user_id" text NOT NULL,
77+
CONSTRAINT "session_token_unique" UNIQUE("token")
78+
);
79+
--> statement-breakpoint
80+
CREATE TABLE "user" (
81+
"id" text PRIMARY KEY NOT NULL,
82+
"name" text NOT NULL,
83+
"email" text NOT NULL,
84+
"email_verified" boolean DEFAULT false NOT NULL,
85+
"image" text,
86+
"utcode_member_at" timestamp with time zone,
87+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
88+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
89+
CONSTRAINT "user_email_unique" UNIQUE("email")
90+
);
91+
--> statement-breakpoint
92+
CREATE TABLE "verification" (
93+
"id" text PRIMARY KEY NOT NULL,
94+
"identifier" text NOT NULL,
95+
"value" text NOT NULL,
96+
"expires_at" timestamp with time zone NOT NULL,
97+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
98+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
99+
);
100+
--> statement-breakpoint
101+
ALTER TABLE "account" ADD CONSTRAINT "account_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
102+
ALTER TABLE "article" ADD CONSTRAINT "article_author_id_member_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."member"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
103+
ALTER TABLE "member" ADD CONSTRAINT "member_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
104+
ALTER TABLE "project_member" ADD CONSTRAINT "project_member_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
105+
ALTER TABLE "project_member" ADD CONSTRAINT "project_member_member_id_member_id_fk" FOREIGN KEY ("member_id") REFERENCES "public"."member"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
106+
ALTER TABLE "session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
107+
CREATE INDEX "account_userId_idx" ON "account" USING btree ("user_id");--> statement-breakpoint
108+
CREATE INDEX "article_authorId_idx" ON "article" USING btree ("author_id");--> statement-breakpoint
109+
CREATE INDEX "member_userId_idx" ON "member" USING btree ("user_id");--> statement-breakpoint
110+
CREATE INDEX "projectMember_pk" ON "project_member" USING btree ("project_id","member_id");--> statement-breakpoint
111+
CREATE INDEX "session_userId_idx" ON "session" USING btree ("user_id");--> statement-breakpoint
112+
CREATE INDEX "verification_identifier_idx" ON "verification" USING btree ("identifier");

drizzle/0000_third_lady_deathstrike.sql

Lines changed: 0 additions & 111 deletions
This file was deleted.

drizzle/0001_windy_true_believers.sql

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)