-
Notifications
You must be signed in to change notification settings - Fork 0
/
Go-bet.sql
97 lines (76 loc) · 2.41 KB
/
Go-bet.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* SQL and ER maded on diagram.io */
CREATE TABLE "users" (
"id" bigserial PRIMARY KEY,
"username" varchar UNIQUE NOT NULL,
"email" varchar(200) UNIQUE NOT NULL,
"phone" varchar(16),
"password" varchar(50) NOT NULL,
"affiliated" bool DEFAULT false,
"created_at" timestamp DEFAULT (now()),
"updated_at" timestamp
);
CREATE TABLE "user_balance" (
"user_id" bigint,
"balance" decimal,
"total_bets" decimal,
"updated_at" timestamp
);
CREATE TABLE "user_info" (
"user_id" bigint,
"birthdate" date,
"cpf" varchar,
"country" varchar,
"uf" varchar,
"cep" varchar,
"address" varchar,
"updated_at" timestamp
);
CREATE TABLE "user_affiliate" (
"sponsor_id" bigint,
"associate_id" bigint,
"created_at" timestamp DEFAULT (now())
);
CREATE TABLE "games" (
"id" integer PRIMARY KEY,
"title" varchar,
"description" varchar(1000),
"created_at" timestamp DEFAULT (now()),
"updated_at" timestamp
);
CREATE TABLE "bets" (
"user_id" bigint,
"game_id" bigint,
"amount" decimal,
"user_lost" bool,
"created_at" timestamp DEFAULT (now())
);
CREATE TABLE "transactions" (
"id" bigserial PRIMARY KEY,
"user_id" bigint,
"transaction_type" varchar NOT NULL,
"amount" decimal NOT NULL,
"transaction_date" timestamp DEFAULT (now())
);
CREATE TABLE "promotions" (
"id" bigserial NOT NULL UNIQUE,
"bonus" decimal NOT NULL,
"quantity" int NOT NULL,
"created_at" timestamp DEFAULT (now())
);
CREATE TABLE "promotions_claimed" (
"id_user" bigint,
"id_promotion" bigint,
"created_at" timestamp DEFAULT (now())
);
CREATE INDEX ON "user_balance" ("user_id");
CREATE INDEX ON "user_info" ("user_id");
CREATE INDEX ON "transactions" ("user_id");
ALTER TABLE "user_balance" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "user_info" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "user_affiliate" ADD FOREIGN KEY ("sponsor_id") REFERENCES "users" ("id");
ALTER TABLE "user_affiliate" ADD FOREIGN KEY ("associate_id") REFERENCES "users" ("id");
ALTER TABLE "bets" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "bets" ADD FOREIGN KEY ("game_id") REFERENCES "games" ("id");
ALTER TABLE "transactions" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "promotions_claimed" ADD FOREIGN KEY ("id_user") REFERENCES "users" ("id");
ALTER TABLE "promotions_claimed" ADD FOREIGN KEY ("id_promotion") REFERENCES "promotions" ("id");