-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
48 lines (44 loc) · 1.63 KB
/
schema.sql
File metadata and controls
48 lines (44 loc) · 1.63 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
CREATE TABLE IF NOT EXISTS exercises (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
description TEXT NOT NULL,
difficulty TEXT CHECK(difficulty IN ('easy', 'medium', 'hard')),
engine TEXT NOT NULL,
tags TEXT DEFAULT '[]',
hints TEXT DEFAULT '[]',
solution TEXT,
starter_code TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS test_cases (
id INTEGER PRIMARY KEY AUTOINCREMENT,
exercise_id INTEGER NOT NULL,
input TEXT,
expected_output TEXT NOT NULL,
is_hidden INTEGER DEFAULT 0,
description TEXT,
FOREIGN KEY (exercise_id) REFERENCES exercises(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS attempts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
exercise_id INTEGER NOT NULL,
code TEXT,
passed INTEGER NOT NULL,
output TEXT,
duration_ms INTEGER,
attempted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (exercise_id) REFERENCES exercises(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS theory_options (
id INTEGER PRIMARY KEY AUTOINCREMENT,
exercise_id INTEGER NOT NULL,
option_number INTEGER NOT NULL,
option_text TEXT NOT NULL,
is_correct INTEGER DEFAULT 0,
FOREIGN KEY (exercise_id) REFERENCES exercises(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_exercises_engine ON exercises(engine);
CREATE INDEX IF NOT EXISTS idx_exercises_difficulty ON exercises(difficulty);
CREATE INDEX IF NOT EXISTS idx_test_cases_exercise ON test_cases(exercise_id);
CREATE INDEX IF NOT EXISTS idx_attempts_exercise ON attempts(exercise_id);