From 53b4ad5d7fd15c0318f1fff819bd8bd4b1ecde91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20F=C3=B6rtsch?= Date: Tue, 3 Mar 2026 15:43:45 +0100 Subject: [PATCH] add initial drizzle migration for postgresql schema Co-Authored-By: Claude Opus 4.6 --- drizzle/0000_parched_valeria_richards.sql | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 drizzle/0000_parched_valeria_richards.sql diff --git a/drizzle/0000_parched_valeria_richards.sql b/drizzle/0000_parched_valeria_richards.sql new file mode 100644 index 0000000..c4f0ecb --- /dev/null +++ b/drizzle/0000_parched_valeria_richards.sql @@ -0,0 +1,46 @@ +CREATE TABLE "movies" ( + "id" serial PRIMARY KEY NOT NULL, + "round_uuid" char(36) NOT NULL, + "title" varchar(60) NOT NULL, + "added_by" varchar(30) NOT NULL, + "added_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +CREATE TABLE "round_history" ( + "id" serial PRIMARY KEY NOT NULL, + "round_uuid" char(36) NOT NULL, + "winner" varchar(60), + "movies_json" text NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +CREATE TABLE "round_users" ( + "round_uuid" char(36) NOT NULL, + "name" varchar(30) NOT NULL, + "done_phase1" boolean DEFAULT false NOT NULL, + "done_phase2" boolean DEFAULT false NOT NULL, + "sort_order" integer DEFAULT 0 NOT NULL, + CONSTRAINT "round_users_round_uuid_name_pk" PRIMARY KEY("round_uuid","name") +); +--> statement-breakpoint +CREATE TABLE "rounds" ( + "uuid" char(36) PRIMARY KEY NOT NULL, + "phase" smallint DEFAULT 1 NOT NULL, + "setup_done" boolean DEFAULT false NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + "updated_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +CREATE TABLE "votes" ( + "round_uuid" char(36) NOT NULL, + "user_name" varchar(30) NOT NULL, + "movie_title" varchar(60) NOT NULL, + "rating" smallint NOT NULL, + CONSTRAINT "votes_round_uuid_user_name_movie_title_pk" PRIMARY KEY("round_uuid","user_name","movie_title") +); +--> statement-breakpoint +ALTER TABLE "movies" ADD CONSTRAINT "movies_round_uuid_rounds_uuid_fk" FOREIGN KEY ("round_uuid") REFERENCES "public"."rounds"("uuid") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "round_history" ADD CONSTRAINT "round_history_round_uuid_rounds_uuid_fk" FOREIGN KEY ("round_uuid") REFERENCES "public"."rounds"("uuid") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "round_users" ADD CONSTRAINT "round_users_round_uuid_rounds_uuid_fk" FOREIGN KEY ("round_uuid") REFERENCES "public"."rounds"("uuid") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "votes" ADD CONSTRAINT "votes_round_uuid_rounds_uuid_fk" FOREIGN KEY ("round_uuid") REFERENCES "public"."rounds"("uuid") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE UNIQUE INDEX "uq_round_title" ON "movies" USING btree ("round_uuid","title"); \ No newline at end of file