-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
56 lines (50 loc) · 1.59 KB
/
schema.sql
File metadata and controls
56 lines (50 loc) · 1.59 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
50
51
52
53
54
55
56
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
totp TEXT
);
CREATE TABLE user_informations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL UNIQUE,
name TEXT NOT NULL,
birthday TEXT,
phone TEXT,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE user_comments (
id TEXT PRIMARY KEY,
user_id INTEGER NOT NULL,
content TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE user_follow (
follower INTEGER NOT NULL,
following INTEGER NOT NULL,
FOREIGN KEY (follower) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (following) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE (follower, following)
);
CREATE TABLE posts (
id TEXT PRIMARY KEY,
user_id INTEGER NOT NULL,
description TEXT NOT NULL,
attachment TEXT NOT NULL,
created_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE post_likes (
post_id TEXT NOT NULL,
user_id TEXT NOT NULL,
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE (post_id, user_id)
);
CREATE TABLE post_comments (
post_id TEXT NOT NULL,
comment_id TEXT NOT NULL,
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
FOREIGN KEY (comment_id) REFERENCES user_comments(id) ON DELETE CASCADE,
UNIQUE (post_id, comment_id)
);