-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sql.txt
53 lines (46 loc) · 1.32 KB
/
sql.txt
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
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL
);
CREATE TABLE posts (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
user_id INTEGER NOT NULL,
link VARCHAR(255) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE sites (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
user_id INTEGER NOT NULL,
link VARCHAR(255) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE comments (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
post_id INTEGER NOT NULL,
text VARCHAR(255) NOT NULL,
FOREIGN KEY (post_id) REFERENCES posts(id)
);
CREATE TABLE options (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
user_id INTEGER NOT NULL,
text VARCHAR(255) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE roles (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL
);
CREATE TABLE user_roles (
user_id INTEGER NOT NULL,
role_id INTEGER NOT NULL,
PRIMARY KEY (user_id, role_id),
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (role_id) REFERENCES roles(id)
);
CREATE TABLE permissions (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
role_id INTEGER NOT NULL,
permission VARCHAR(255) NOT NULL,
FOREIGN KEY (role_id) REFERENCES roles(id)
);