Files
movie-select/drizzle/0000_parched_valeria_richards.sql
2026-03-03 15:43:45 +01:00

46 lines
2.3 KiB
SQL

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");