-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
41 lines (36 loc) · 1.12 KB
/
schema.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
-- schema.sql
PRAGMA foreign_keys = ON;
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
role TEXT NOT NULL DEFAULT 'user'
);
CREATE TABLE IF NOT EXISTS board_messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
author_id INTEGER NOT NULL,
timestamp TEXT NOT NULL,
subject TEXT NOT NULL,
body TEXT NOT NULL,
parent_id INTEGER,
FOREIGN KEY (author_id) REFERENCES users(id),
FOREIGN KEY (parent_id) REFERENCES board_messages(id)
);
CREATE TABLE IF NOT EXISTS private_messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
from_id INTEGER NOT NULL,
to_id INTEGER NOT NULL,
timestamp TEXT NOT NULL,
body TEXT NOT NULL,
read_flag INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (from_id) REFERENCES users(id),
FOREIGN KEY (to_id) REFERENCES users(id)
);
CREATE TABLE IF NOT EXISTS files (
id INTEGER PRIMARY KEY AUTOINCREMENT,
uploader_id INTEGER NOT NULL,
filename TEXT NOT NULL,
description TEXT,
visibility TEXT NOT NULL,
FOREIGN KEY (uploader_id) REFERENCES users(id)
);