aboutsummaryrefslogtreecommitdiffhomepage
path: root/pkgs/server/drizzle/0000_cynical_zeigeist.sql
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-12-03 05:11:21 +0900
committernsfisis <nsfisis@gmail.com>2025-12-04 23:26:20 +0900
commitc3fc3414dfdb8c7d018e792cde6b4b4374d3d573 (patch)
tree7430e62f36bd4407930948e15ce7180186e2af66 /pkgs/server/drizzle/0000_cynical_zeigeist.sql
parent328710be69d218007477fc46f6642a71ac0e385f (diff)
downloadkioku-c3fc3414dfdb8c7d018e792cde6b4b4374d3d573.tar.gz
kioku-c3fc3414dfdb8c7d018e792cde6b4b4374d3d573.tar.zst
kioku-c3fc3414dfdb8c7d018e792cde6b4b4374d3d573.zip
feat(db): add database migrations
Generate initial migration file for all schema tables (users, decks, cards, review_logs) using Drizzle Kit. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'pkgs/server/drizzle/0000_cynical_zeigeist.sql')
-rw-r--r--pkgs/server/drizzle/0000_cynical_zeigeist.sql58
1 files changed, 58 insertions, 0 deletions
diff --git a/pkgs/server/drizzle/0000_cynical_zeigeist.sql b/pkgs/server/drizzle/0000_cynical_zeigeist.sql
new file mode 100644
index 0000000..3034102
--- /dev/null
+++ b/pkgs/server/drizzle/0000_cynical_zeigeist.sql
@@ -0,0 +1,58 @@
+CREATE TABLE "cards" (
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
+ "deck_id" uuid NOT NULL,
+ "front" text NOT NULL,
+ "back" text NOT NULL,
+ "state" smallint DEFAULT 0 NOT NULL,
+ "due" timestamp with time zone DEFAULT now() NOT NULL,
+ "stability" real DEFAULT 0 NOT NULL,
+ "difficulty" real DEFAULT 0 NOT NULL,
+ "elapsed_days" integer DEFAULT 0 NOT NULL,
+ "scheduled_days" integer DEFAULT 0 NOT NULL,
+ "reps" integer DEFAULT 0 NOT NULL,
+ "lapses" integer DEFAULT 0 NOT NULL,
+ "last_review" timestamp with time zone,
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
+ "deleted_at" timestamp with time zone,
+ "sync_version" integer DEFAULT 0 NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "decks" (
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
+ "user_id" uuid NOT NULL,
+ "name" varchar(255) NOT NULL,
+ "description" text,
+ "new_cards_per_day" integer DEFAULT 20 NOT NULL,
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
+ "deleted_at" timestamp with time zone,
+ "sync_version" integer DEFAULT 0 NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "review_logs" (
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
+ "card_id" uuid NOT NULL,
+ "user_id" uuid NOT NULL,
+ "rating" smallint NOT NULL,
+ "state" smallint NOT NULL,
+ "scheduled_days" integer NOT NULL,
+ "elapsed_days" integer NOT NULL,
+ "reviewed_at" timestamp with time zone DEFAULT now() NOT NULL,
+ "duration_ms" integer,
+ "sync_version" integer DEFAULT 0 NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "users" (
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
+ "username" varchar(255) NOT NULL,
+ "password_hash" varchar(255) NOT NULL,
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
+ CONSTRAINT "users_username_unique" UNIQUE("username")
+);
+--> statement-breakpoint
+ALTER TABLE "cards" ADD CONSTRAINT "cards_deck_id_decks_id_fk" FOREIGN KEY ("deck_id") REFERENCES "public"."decks"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "decks" ADD CONSTRAINT "decks_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "review_logs" ADD CONSTRAINT "review_logs_card_id_cards_id_fk" FOREIGN KEY ("card_id") REFERENCES "public"."cards"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "review_logs" ADD CONSTRAINT "review_logs_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action; \ No newline at end of file