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