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 <[email protected]>
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
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"devDependencies": {
1717
"@eslint/compat": "^1.4.0",
1818
"@eslint/js": "^9.39.1",
19-
"@libsql/client": "^0.15.15",
2019
"@sveltejs/adapter-auto": "^7.0.0",
2120
"@sveltejs/adapter-cloudflare": "^7.2.4",
2221
"@sveltejs/kit": "^2.49.1",
@@ -32,6 +31,7 @@
3231
"eslint-config-prettier": "^10.1.8",
3332
"eslint-plugin-svelte": "^3.13.1",
3433
"globals": "^16.5.0",
34+
"postgres": "^3.4.5",
3535
"prettier": "^3.7.4",
3636
"prettier-plugin-svelte": "^3.4.0",
3737
"prettier-plugin-tailwindcss": "^0.7.2",
@@ -496,7 +496,7 @@
496496

497497
"defu": ["[email protected]", "", {}, "sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg=="],
498498

499-
"detect-libc": ["detect-libc@2.0.2", "", {}, "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw=="],
499+
"detect-libc": ["detect-libc@2.1.2", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
500500

501501
"devalue": ["[email protected]", "", {}, "sha512-jDwizj+IlEZBunHcOuuFVBnIMPAEHvTsJj0BcIp94xYguLRVBcXO853px/MyIJvbVzWdsGvrRweIUWJw8hBP7A=="],
502502

@@ -792,6 +792,8 @@
792792

793793
"postcss-selector-parser": ["[email protected]", "", { "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" } }, "sha512-IQ7TZdoaqbT+LCpShg46jnZVlhWD2w6iQYAcYXfHARZ7X1t/UGhhceQDs5X0cGqKvYlHNOuv7Oa1xmb0oQuA3w=="],
794794

795+
"postgres": ["[email protected]", "", {}, "sha512-Jtc2612XINuBjIl/QTWsV5UvE8UHuNblcO3vVADSrKsrc6RqGX6lOW1cEo3CM2v0XG4Nat8nI+YM7/f26VxXLw=="],
796+
795797
"prelude-ls": ["[email protected]", "", {}, "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g=="],
796798

797799
"prettier": ["[email protected]", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-v6UNi1+3hSlVvv8fSaoUbggEM5VErKmmpGA7Pl3HF8V6uKY7rvClBOJlH6yNwQtfTueNkGVpOv/mtWL9L4bgRA=="],
@@ -1004,7 +1006,7 @@
10041006

10051007
"debug/ms": ["[email protected]", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
10061008

1007-
"lightningcss/detect-libc": ["detect-libc@2.1.2", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
1009+
"libsql/detect-libc": ["detect-libc@2.0.2", "", {}, "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw=="],
10081010

10091011
"miniflare/acorn": ["[email protected]", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="],
10101012

@@ -1014,8 +1016,6 @@
10141016

10151017
"postcss-load-config/yaml": ["[email protected]", "", {}, "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg=="],
10161018

1017-
"sharp/detect-libc": ["[email protected]", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
1018-
10191019
"svelte-eslint-parser/postcss-selector-parser": ["[email protected]", "", { "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" } }, "sha512-orRsuYpJVw8LdAwqqLykBj9ecS5/cRHlI5+nvTo8LcCKmzDmqVORXtOIYEEQuL9D4BxtA1lm5isAqzQZCoQ6Eg=="],
10201020

10211021
"wrangler/esbuild": ["[email protected]", "", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.27.0", "@esbuild/android-arm": "0.27.0", "@esbuild/android-arm64": "0.27.0", "@esbuild/android-x64": "0.27.0", "@esbuild/darwin-arm64": "0.27.0", "@esbuild/darwin-x64": "0.27.0", "@esbuild/freebsd-arm64": "0.27.0", "@esbuild/freebsd-x64": "0.27.0", "@esbuild/linux-arm": "0.27.0", "@esbuild/linux-arm64": "0.27.0", "@esbuild/linux-ia32": "0.27.0", "@esbuild/linux-loong64": "0.27.0", "@esbuild/linux-mips64el": "0.27.0", "@esbuild/linux-ppc64": "0.27.0", "@esbuild/linux-riscv64": "0.27.0", "@esbuild/linux-s390x": "0.27.0", "@esbuild/linux-x64": "0.27.0", "@esbuild/netbsd-arm64": "0.27.0", "@esbuild/netbsd-x64": "0.27.0", "@esbuild/openbsd-arm64": "0.27.0", "@esbuild/openbsd-x64": "0.27.0", "@esbuild/openharmony-arm64": "0.27.0", "@esbuild/sunos-x64": "0.27.0", "@esbuild/win32-arm64": "0.27.0", "@esbuild/win32-ia32": "0.27.0", "@esbuild/win32-x64": "0.27.0" }, "bin": { "esbuild": "bin/esbuild" } }, "sha512-jd0f4NHbD6cALCyGElNpGAOtWxSq46l9X/sWB0Nzd5er4Kz2YTm+Vl0qKFT9KUJvD8+fiO8AvoHhFvEatfVixA=="],

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)