-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.sql
61 lines (53 loc) · 1.77 KB
/
db.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
create table games
(
ID int not null,
dateStarted datetime default CURRENT_TIMESTAMP not null,
constraint games_ID_uindex
unique (ID)
);
alter table games
add primary key (ID);
alter table games
modify ID int auto_increment;
create table players
(
ID int not null,
name varchar(64) not null,
gameID int not null,
constraint players_ID_uindex
unique (ID),
constraint players_pk
unique (name, gameID),
constraint players_games_ID_fk
foreign key (gameID) references games (ID)
on update cascade on delete cascade
);
alter table players
add primary key (ID);
alter table players
modify ID int auto_increment;
create table transactions
(
ID int not null,
`from` int null,
`to` int null,
gameID int not null,
value bigint not null,
description text null,
date datetime default CURRENT_TIMESTAMP not null,
constraint transactions_ID_uindex
unique (ID),
constraint transactions_games_ID_fk
foreign key (gameID) references games (ID)
on update cascade on delete cascade,
constraint transactions_players_ID_fk
foreign key (`from`) references players (ID)
on update cascade on delete cascade,
constraint transactions_players_ID_fk_2
foreign key (`to`) references players (ID)
on update cascade on delete cascade
);
alter table transactions
add primary key (ID);
alter table transactions
modify ID int auto_increment;