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