Draft of a problems section + news system
[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 );
19
20 create table Problems (
21 id integer primary key,
22 added datetime,
23 fen varchar,
24 uid integer,
25 vid integer,
26 instruction text,
27 solution text,
28 foreign key (uid) references Users(id),
29 foreign key (vid) references Variants(id)
30 );
31
32 create table News (
33 id integer primary key,
34 uid integer,
35 added datetime,
36 content text,
37 foreign key (uid) references Users(id)
38 );
39
40 create table Challenges (
41 id integer primary key,
42 added datetime,
43 uid integer,
44 target integer,
45 vid integer,
46 fen varchar,
47 cadence varchar,
48 foreign key (uid) references Users(id),
49 foreign key (vid) references Variants(id)
50 );
51
52 create table Games (
53 id integer primary key,
54 vid integer,
55 fenStart varchar, --initial state
56 fen varchar, --current state
57 score varchar,
58 scoreMsg varchar,
59 cadence varchar,
60 created datetime,
61 drawOffer character,
62 foreign key (vid) references Variants(id)
63 );
64
65 create table Chats (
66 gid integer,
67 name varchar,
68 msg varchar,
69 added datetime
70 );
71
72 -- Store informations about players in a corr game
73 create table Players (
74 gid integer,
75 uid integer,
76 color character,
77 foreign key (gid) references Games(id),
78 foreign key (uid) references Users(id)
79 );
80
81 create table Moves (
82 gid integer,
83 squares varchar, --description, appear/vanish/from/to
84 played datetime, --when was this move played?
85 idx integer, --index of the move in the game
86 foreign key (gid) references Games(id)
87 );
88
89 pragma foreign_keys = on;