'update'
[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,
83494c7f 16 created datetime,
bf20f404 17 notify boolean
8d7e2786
BA
18);
19
8d7e2786 20-- All the following tables are for correspondance play only
bebcc8d4 21-- (Live games are stored in browser)
8d7e2786
BA
22
23create table Challenges (
bf20f404
BA
24 id integer primary key,
25 added datetime,
26 uid integer,
27 target integer,
28 vid integer,
29 fen varchar,
30 timeControl varchar,
31 foreign key (uid) references Users(id),
32 foreign key (vid) references Variants(id)
8d7e2786
BA
33);
34
92a523d1 35-- NOTE: no need for a "created" field, it's deduced from first move playing time
8d7e2786 36create table Games (
bf20f404
BA
37 id integer primary key,
38 vid integer,
39 fenStart varchar, --initial state
40 fen varchar, --current state
41 score varchar,
bebcc8d4 42 timeControl varchar,
d431028c 43 created datetime, --used only for DB cleaning
b7cbbda1 44 drawOffer boolean,
bf20f404 45 foreign key (vid) references Variants(id)
8d7e2786
BA
46);
47
63ca2b89
BA
48create table Chats (
49 gid integer,
c547fbfb
BA
50 name varchar,
51 msg varchar,
52 added datetime,
63ca2b89
BA
53);
54
8d7e2786
BA
55-- Store informations about players in a corr game
56create table Players (
bf20f404
BA
57 gid integer,
58 uid integer,
59 color character,
bf20f404
BA
60 foreign key (gid) references Games(id),
61 foreign key (uid) references Users(id)
8d7e2786
BA
62);
63
64create table Moves (
bf20f404 65 gid integer,
f41ce580 66 squares varchar, --description, appear/vanish/from/to
bf20f404
BA
67 played datetime, --when was this move played?
68 idx integer, --index of the move in the game
bf20f404 69 foreign key (gid) references Games(id)
da06a6eb 70);
c326e657 71
8d7e2786 72pragma foreign_keys = on;