21 lines
No EOL
1.3 KiB
SQL
21 lines
No EOL
1.3 KiB
SQL
CREATE TABLE "lobbies" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"code" varchar(10) NOT NULL,
|
|
"host_user_id" text NOT NULL,
|
|
"status" varchar(20) NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
CONSTRAINT "lobbies_code_unique" UNIQUE("code"),
|
|
CONSTRAINT "lobby_status_check" CHECK ("lobbies"."status" IN ('waiting', 'in_progress', 'finished'))
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "lobby_players" (
|
|
"lobby_id" uuid NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"score" integer DEFAULT 0 NOT NULL,
|
|
"joined_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
CONSTRAINT "lobby_players_lobby_id_user_id_pk" PRIMARY KEY("lobby_id","user_id")
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "lobbies" ADD CONSTRAINT "lobbies_host_user_id_user_id_fk" FOREIGN KEY ("host_user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "lobby_players" ADD CONSTRAINT "lobby_players_lobby_id_lobbies_id_fk" FOREIGN KEY ("lobby_id") REFERENCES "public"."lobbies"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "lobby_players" ADD CONSTRAINT "lobby_players_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; |