-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ddl.sql
125 lines (110 loc) · 4.5 KB
/
ddl.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
create database team;
\c team
-- Tables
create table users (
id serial primary key,
username varchar(255) NOT NULL,
password varchar(255),
icon_url varchar(2048),
email varchar(255),
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE(username)
);
create table posts (
id serial primary key,
kind varchar(255) NOT NULL,
user_id serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
title varchar(255) NOT NULL,
body text NOT NULL,
status varchar(255) NOT NULL,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE posts ADD COLUMN shared boolean DEFAULT false;
create table post_comments (
id serial primary key,
user_id serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
post_id serial REFERENCES posts (id) ON DELETE CASCADE NOT NULL,
body text NOT NULL,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table tags (
id serial primary key,
name varchar(255) NOT NULL,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table taggings (
id serial primary key,
tag_id serial REFERENCES tags (id) ON DELETE CASCADE NOT NULL,
post_id serial REFERENCES posts (id) ON DELETE CASCADE NOT NULL,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table stocks (
id serial primary key,
user_id serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
post_id serial REFERENCES posts (id) ON DELETE CASCADE NOT NULL,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table gists (
id serial primary key,
user_id serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
description varchar(255),
filename varchar(255),
code text NOT NULL,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table gist_comments (
id serial primary key,
user_id serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
gist_id serial REFERENCES gists (id) ON DELETE CASCADE NOT NULL,
body text NOT NULL,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table tweets (
id serial primary key,
user_id serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
body text NOT NULL,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table tweet_comments (
id serial primary key,
user_id serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
tweet_id serial REFERENCES tweets (id) ON DELETE CASCADE NOT NULL,
body text NOT NULL,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table notifications (
id serial primary key,
path varchar(255),
from_user serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
to_user serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
body text NOT NULL,
read boolean DEFAULT false,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table preferences (
id serial primary key,
user_id serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
menu varchar(1024),
theme varchar(1024),
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
create table pinneds (
id serial primary key,
post_id serial REFERENCES posts (id) ON DELETE CASCADE NOT NULL,
user_id serial REFERENCES users (id) ON DELETE CASCADE NOT NULL,
deleted boolean DEFAULT false,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);