-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
49 lines (42 loc) · 1.41 KB
/
schema.sql
File metadata and controls
49 lines (42 loc) · 1.41 KB
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
PRAGMA foreign_keys = ON ;
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
created_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS tasks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
work_name TEXT NOT NULL,
description TEXT NOT NULL,
extended_description TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS attempts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
task_id INTEGER NOT NULL,
timestamp TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
FOREIGN KEY (task_id) REFERENCES tasks (id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS attempt_tests (
id INTEGER PRIMARY KEY AUTOINCREMENT,
attempt_id INTEGER NOT NULL,
description TEXT NOT NULL,
result INTEGER NOT NULL,
FOREIGN KEY (attempt_id) REFERENCES attempts (id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS user_task_statuses (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
task_id INTEGER NOT NULL,
status INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
FOREIGN KEY (task_id) REFERENCES tasks (id) ON DELETE CASCADE,
UNIQUE(user_id, task_id)
);
CREATE TABLE IF NOT EXISTS schema_migrations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
migration_name TEXT NOT NULL UNIQUE,
applied_at TEXT NOT NULL
);