Experimental news notification system + fix Eightpieces variant
[vchess.git] / server / db / create.sql
1 -- Database should be in this folder, and named 'vchess.sqlite'
2
3 create table Variants (
4 id integer primary key,
5 name varchar unique,
6 description text
7 );
8
9 create table Users (
10 id integer primary key,
11 name varchar unique,
12 email varchar unique,
13 loginToken varchar,
14 loginTime datetime,
15 sessionToken varchar,
16 created datetime,
17 notify boolean,
18 newsRead datetime
19 );
20
21 create table Problems (
22 id integer primary key,
23 added datetime,
24 fen varchar,
25 uid integer,
26 vid integer,
27 instruction text,
28 solution text,
29 foreign key (uid) references Users(id),
30 foreign key (vid) references Variants(id)
31 );
32
33 create table News (
34 id integer primary key,
35 uid integer,
36 added datetime,
37 content text,
38 foreign key (uid) references Users(id)
39 );
40
41 create table Challenges (
42 id integer primary key,
43 added datetime,
44 uid integer,
45 target integer,
46 vid integer,
47 randomness integer,
48 fen varchar,
49 cadence varchar,
50 foreign key (uid) references Users(id),
51 foreign key (vid) references Variants(id)
52 );
53
54 create table Games (
55 id integer primary key,
56 vid integer,
57 fenStart varchar, --initial state
58 fen varchar, --current state
59 score varchar default '*',
60 scoreMsg varchar,
61 cadence varchar,
62 randomness integer, --for rematch
63 created datetime,
64 drawOffer character default '',
65 rematchOffer character default '',
66 deletedByWhite boolean,
67 deletedByBlack boolean,
68 foreign key (vid) references Variants(id)
69 );
70
71 create table Chats (
72 gid integer,
73 name varchar,
74 msg varchar,
75 added datetime
76 );
77
78 -- Store informations about players in a corr game
79 create table Players (
80 gid integer,
81 uid integer,
82 color character,
83 foreign key (gid) references Games(id),
84 foreign key (uid) references Users(id)
85 );
86
87 create table Moves (
88 gid integer,
89 squares varchar, --description, appear/vanish/from/to
90 played datetime, --when was this move played?
91 idx integer, --index of the move in the game
92 foreign key (gid) references Games(id)
93 );
94
95 pragma foreign_keys = on;