Attempt to fix countdown for live games. Some issues with GameStorage.add now
[vchess.git] / server / db / create.sql
CommitLineData
c326e657 1-- Database should be in this folder, and named 'vchess.sqlite'
86c9843c 2
da06a6eb 3create table Variants (
bf20f404
BA
4 id integer primary key,
5 name varchar unique,
6 description text
da06a6eb 7);
da06a6eb 8
8d7e2786 9create table Users (
bf20f404
BA
10 id integer primary key,
11 name varchar unique,
12 email varchar unique,
13 loginToken varchar,
14 loginTime datetime,
15 sessionToken varchar,
16 notify boolean
8d7e2786
BA
17);
18
da06a6eb 19create table Problems (
bf20f404
BA
20 id integer primary key,
21 added datetime,
22 uid integer,
23 vid integer,
24 fen varchar,
25 instructions text,
26 solution text,
27 foreign key (uid) references Users(id),
28 foreign key (vid) references Variants(id)
8d7e2786
BA
29);
30
31-- All the following tables are for correspondance play only
bebcc8d4 32-- (Live games are stored in browser)
8d7e2786
BA
33
34create table Challenges (
bf20f404
BA
35 id integer primary key,
36 added datetime,
37 uid integer,
38 target integer,
39 vid integer,
40 fen varchar,
41 timeControl varchar,
42 foreign key (uid) references Users(id),
43 foreign key (vid) references Variants(id)
8d7e2786
BA
44);
45
c0b27606 46-- NOTE: no need for a "created" field, it's deduce from first move playing time
8d7e2786 47create table Games (
bf20f404
BA
48 id integer primary key,
49 vid integer,
50 fenStart varchar, --initial state
51 fen varchar, --current state
52 score varchar,
bebcc8d4 53 timeControl varchar,
bf20f404 54 foreign key (vid) references Variants(id)
8d7e2786
BA
55);
56
57-- Store informations about players in a corr game
58create table Players (
bf20f404
BA
59 gid integer,
60 uid integer,
61 color character,
62 rtime integer, --remaining time in milliseconds
63 foreign key (gid) references Games(id),
64 foreign key (uid) references Users(id)
8d7e2786
BA
65);
66
67create table Moves (
bf20f404
BA
68 gid integer,
69 move varchar,
70 message varchar,
71 played datetime, --when was this move played?
72 idx integer, --index of the move in the game
73 color character, --required for e.g. Marseillais Chess
74 foreign key (gid) references Games(id)
da06a6eb 75);
c326e657 76
8d7e2786 77pragma foreign_keys = on;