Move 'anonymousCount' which was computed to a method in Hall. Seems more accurate
[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 newsRead datetime
19 );
20
21 create table Problems (
22 id integer primary key,
23 added datetime,
24 fen varchar,
25 uid integer,
26 vid integer,
27 instruction text,
28 solution text,
29 foreign key (uid) references Users(id),
30 foreign key (vid) references Variants(id)
31 );
32
33 create table News (
34 id integer primary key,
35 uid integer,
36 added datetime,
37 content text,
38 foreign key (uid) references Users(id)
39 );
40
41 create table Challenges (
42 id integer primary key,
43 added datetime,
44 uid integer,
45 target integer,
46 vid integer,
47 randomness integer,
48 fen varchar,
49 cadence varchar,
50 foreign key (uid) references Users(id),
51 foreign key (vid) references Variants(id)
52 );
53
54 create table Games (
55 id integer primary key,
56 vid integer,
57 fenStart varchar, --initial state
58 fen varchar, --current state
59 white integer,
60 black integer,
61 score varchar default '*',
62 scoreMsg varchar,
63 cadence varchar,
64 randomness integer, --for rematch
65 created datetime,
66 drawOffer character default '',
67 rematchOffer character default '',
68 deletedByWhite boolean,
69 deletedByBlack boolean,
70 foreign key (vid) references Variants(id),
71 foreign key (white) references Users(id),
72 foreign key (black) references Users(id)
73 );
74
75 create table Chats (
76 gid integer,
77 name varchar,
78 msg varchar,
79 added datetime
80 );
81
82 create table Moves (
83 gid integer,
84 squares varchar, --description, appear/vanish/from/to
85 played datetime, --when was this move played?
86 idx integer, --index of the move in the game
87 foreign key (gid) references Games(id)
88 );
89
90 create index scoreIdx on Games(score);
91
92 pragma foreign_keys = on;