-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCodeHero_postgres_create.sql
52 lines (36 loc) · 1.13 KB
/
CodeHero_postgres_create.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
CREATE TABLE "Users" (
"id" serial NOT NULL,
"username" varchar(20) NOT NULL UNIQUE,
"password" varchar(20) NOT NULL,
CONSTRAINT "Users_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
CREATE TABLE "Games" (
"id" serial NOT NULL,
"code_block_id" serial NOT NULL,
"winner_id" serial NOT NULL,
CONSTRAINT "Games_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
CREATE TABLE "CodeBlocks" (
"id" serial NOT NULL,
"text" varchar NOT NULL,
CONSTRAINT "CodeBlocks_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
CREATE TABLE "Users_Games" (
"id" serial NOT NULL,
"game_id" int NOT NULL,
"user_id" int NOT NULL,
"time" int NOT NULL,
CONSTRAINT "Users_Games_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
ALTER TABLE "Games" ADD CONSTRAINT "Games_fk0" FOREIGN KEY ("code_block_id") REFERENCES "CodeBlocks"("id");
ALTER TABLE "Games" ADD CONSTRAINT "Games_fk1" FOREIGN KEY ("winner_id") REFERENCES "Users"("id");
ALTER TABLE "Users_Games" ADD CONSTRAINT "Users_Games_fk0" FOREIGN KEY ("game_id") REFERENCES "Games"("id");
ALTER TABLE "Users_Games" ADD CONSTRAINT "Users_Games_fk1" FOREIGN KEY ("user_id") REFERENCES "Users"("id");