-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration.sql
51 lines (47 loc) · 1.56 KB
/
migration.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
CREATE TABLE
IF NOT EXISTS questions (
level INTEGER PRIMARY KEY NOT NULL,
scene INTEGER NOT NULL DEFAULT 1,
text TEXT NOT NULL,
points INTEGER NOT NULL DEFAULT 0,
hidden BOOLEAN NOT NULL DEFAULT FALSE,
url TEXT,
answer TEXT NOT NULL
);
CREATE TABLE
IF NOT EXISTS special_challenges (
level INTEGER PRIMARY KEY NOT NULL,
text TEXT NOT NULL,
link TEXT,
points INTEGER NOT NULL DEFAULT 0,
answer TEXT NOT NULL
);
CREATE TABLE
IF NOT EXISTS users (
username TEXT PRIMARY KEY NOT NULL CHECK(
LENGTH(username) BETWEEN 3 AND 20
),
avatar TEXT NOT NULL,
password TEXT NOT NULL,
member_1_name TEXT NOT NULL,
member_2_name TEXT NOT NULL,
member_3_name TEXT NOT NULL,
member_1_regno TEXT NOT NULL,
member_2_regno TEXT NOT NULL,
member_3_regno TEXT NOT NULL,
level INTEGER NOT NULL DEFAULT 1,
scene_reached NOT NULL DEFAULT 1,
points INTEGER NOT NULL DEFAULT 0,
answered_levels TEXT NOT NULL DEFAULT '[]',
answered_special_challenges TEXT NOT NULL DEFAULT '[]',
reachedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE
IF NOT EXISTS attempts (
username TEXT NOT NULL REFERENCES users(username),
level INTEGER NOT NULL REFERENCES questions(level),
attempt TEXT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX
IF NOT EXISTS leaderboard ON users(level DESC, reachedAt ASC);