-
Notifications
You must be signed in to change notification settings - Fork 0
/
pastebin.sql
105 lines (71 loc) · 2.2 KB
/
pastebin.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
CREATE TABLE pastes (
id serial,
title varchar default NULL,
content text,
lang varchar default NULL,
poster varchar default NULL,
user_id integer,
created_on timestamp,
updated_on timestamp default NULL,
PRIMARY KEY (id)
);
CREATE TABLE users (
id serial,
username varchar default NULL,
name varchar default NULL,
email varchar default NULL,
password varchar default NULL,
PRIMARY KEY (id)
);
CREATE TABLE active (
id serial,
user_id integer default NULL REFERENCES pastes (id) ON DELETE SET NULL ON UPDATE SET NULL,
logged_on integer default NULL,
PRIMARY KEY (id)
);
CREATE TABLE forks (
id serial,
paste_id integer default NULL REFERENCES pastes (id) ON DELETE CASCADE ON UPDATE CASCADE,
fork_id integer default NULL REFERENCES pastes (id) ON DELETE CASCADE ON UPDATE CASCADE,
created_on timestamp default NULL,
PRIMARY KEY (id)
);
CREATE TABLE revisions (
id serial,
paste_id integer default NULL REFERENCES pastes (id) ON DELETE CASCADE ON UPDATE CASCADE,
revision_id integer default NULL REFERENCES pastes (id) ON DELETE CASCADE ON UPDATE CASCADE,
version integer,
PRIMARY KEY (id)
);
CREATE TABLE roles (
id serial,
role varchar default NULL,
PRIMARY KEY (id)
);
CREATE TABLE user_role (
id serial,
user_id integer default '0' REFERENCES users (id) ON DELETE CASCADE,
role_id integer default '1' REFERENCES roles (id) ON DELETE SET DEFAULT,
PRIMARY KEY(id)
);
CREATE TABLE notifications (
id serial,
user_id integer default NULL REFERENCES users (id) ON DELETE CASCADE,
message text,
created_on integer,
sent_on integer,
PRIMARY KEY (id)
);
CREATE TABLE links (
id serial,
shortlink varchar(32),
link varchar(1024),
user_id integer default NULL REFERENCES users (id) ON DELETE CASCADE,
created_on integer,
PRIMARY KEY (id)
);
INSERT INTO users (username, name, email, password) VALUES ('admin','Admini Strator','[email protected]','21232f297a57a5a743894a0e4a801fc3');
INSERT INTO roles (role) VALUES ('user');
INSERT INTO roles (role) VALUES ('admin');
INSERT INTO user_role (user_id, role_id) VALUES (1, 2);
ALTER TABLE pastes ADD CONSTRAINT user_id_ibfk FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;