CREATE TYPE "public"."act" AS ENUM('lobby', 'act1', 'act2', 'act3', 'ended');--> statement-breakpoint CREATE TYPE "public"."jury_round_status" AS ENUM('open', 'closed');--> statement-breakpoint CREATE TYPE "public"."quiz_round_status" AS ENUM('showing', 'buzzing', 'judging', 'resolved');--> statement-breakpoint CREATE TABLE "bingo_cards" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "player_id" uuid NOT NULL, "room_id" uuid NOT NULL, "squares" jsonb NOT NULL ); --> statement-breakpoint CREATE TABLE "dish_guesses" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "player_id" uuid NOT NULL, "dish_id" uuid NOT NULL, "guessed_country" varchar NOT NULL ); --> statement-breakpoint CREATE TABLE "dishes" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "room_id" uuid NOT NULL, "name" varchar(100) NOT NULL, "correct_country" varchar NOT NULL, "revealed" boolean DEFAULT false NOT NULL ); --> statement-breakpoint CREATE TABLE "jury_rounds" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "room_id" uuid NOT NULL, "country_code" varchar NOT NULL, "status" "jury_round_status" DEFAULT 'open' NOT NULL, "opened_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "jury_votes" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "player_id" uuid NOT NULL, "jury_round_id" uuid NOT NULL, "rating" integer NOT NULL ); --> statement-breakpoint CREATE TABLE "players" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "room_id" uuid NOT NULL, "session_id" uuid NOT NULL, "display_name" varchar(20) NOT NULL, "is_host" boolean DEFAULT false NOT NULL, "connected" boolean DEFAULT false NOT NULL, "joined_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "players_session_id_unique" UNIQUE("session_id") ); --> statement-breakpoint CREATE TABLE "predictions" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "player_id" uuid NOT NULL, "room_id" uuid NOT NULL, "predicted_winner" varchar NOT NULL, "top_3" jsonb NOT NULL, "nul_points_pick" varchar NOT NULL ); --> statement-breakpoint CREATE TABLE "quiz_answers" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "player_id" uuid NOT NULL, "quiz_round_id" uuid NOT NULL, "buzzed_at" timestamp DEFAULT now() NOT NULL, "correct" boolean ); --> statement-breakpoint CREATE TABLE "quiz_rounds" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "room_id" uuid NOT NULL, "question_id" varchar NOT NULL, "status" "quiz_round_status" DEFAULT 'showing' NOT NULL ); --> statement-breakpoint CREATE TABLE "rooms" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "code" varchar(4) NOT NULL, "current_act" "act" DEFAULT 'lobby' NOT NULL, "host_session_id" uuid NOT NULL, "actual_winner" varchar, "actual_second" varchar, "actual_third" varchar, "actual_last" varchar, "created_at" timestamp DEFAULT now() NOT NULL, "expires_at" timestamp NOT NULL, CONSTRAINT "rooms_code_unique" UNIQUE("code") ); --> statement-breakpoint ALTER TABLE "bingo_cards" ADD CONSTRAINT "bingo_cards_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "bingo_cards" ADD CONSTRAINT "bingo_cards_room_id_rooms_id_fk" FOREIGN KEY ("room_id") REFERENCES "public"."rooms"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "dish_guesses" ADD CONSTRAINT "dish_guesses_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "dish_guesses" ADD CONSTRAINT "dish_guesses_dish_id_dishes_id_fk" FOREIGN KEY ("dish_id") REFERENCES "public"."dishes"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "dishes" ADD CONSTRAINT "dishes_room_id_rooms_id_fk" FOREIGN KEY ("room_id") REFERENCES "public"."rooms"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "jury_rounds" ADD CONSTRAINT "jury_rounds_room_id_rooms_id_fk" FOREIGN KEY ("room_id") REFERENCES "public"."rooms"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "jury_votes" ADD CONSTRAINT "jury_votes_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "jury_votes" ADD CONSTRAINT "jury_votes_jury_round_id_jury_rounds_id_fk" FOREIGN KEY ("jury_round_id") REFERENCES "public"."jury_rounds"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "players" ADD CONSTRAINT "players_room_id_rooms_id_fk" FOREIGN KEY ("room_id") REFERENCES "public"."rooms"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "predictions" ADD CONSTRAINT "predictions_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "predictions" ADD CONSTRAINT "predictions_room_id_rooms_id_fk" FOREIGN KEY ("room_id") REFERENCES "public"."rooms"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "quiz_answers" ADD CONSTRAINT "quiz_answers_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "quiz_answers" ADD CONSTRAINT "quiz_answers_quiz_round_id_quiz_rounds_id_fk" FOREIGN KEY ("quiz_round_id") REFERENCES "public"."quiz_rounds"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "quiz_rounds" ADD CONSTRAINT "quiz_rounds_room_id_rooms_id_fk" FOREIGN KEY ("room_id") REFERENCES "public"."rooms"("id") ON DELETE no action ON UPDATE no action;