· 4 years ago · Feb 06, 2021, 11:52 AM
1drop table if exists comment CASCADE
2drop table if exists post CASCADE
3drop table if exists subreddit CASCADE
4drop table if exists subreddit_posts CASCADE
5drop table if exists user CASCADE
6drop table if exists vote CASCADE
7
8create table comment (
9 id bigint generated by default as identity,
10 comment_text varchar(255),
11 post_id bigint,
12 user_id bigint,
13 primary key (id)
14)
15
16create table post (
17 post_id bigint generated by default as identity,
18 description varchar(255),
19 title varchar(255),
20 vote_count integer,
21 id bigint,
22 user_id bigint,
23 primary key (post_id)
24)
25
26create table subreddit (
27 id bigint generated by default as identity,
28 subredditname varchar(255),
29 user_user_id bigint,
30 primary key (id)
31)
32
33create table subreddit_posts (
34 subreddit_id bigint not null,
35 posts_post_id bigint not null
36)
37
38create table user (
39 user_id bigint generated by default as identity,
40 email varchar(255),
41 password varchar(255),
42 username varchar(255),
43 primary key (user_id)
44)
45
46create table vote (
47 vote_id bigint generated by default as identity,
48 vote_type integer,
49 post_id bigint not null,
50 user_id bigint,
51 primary key (vote_id)
52)
53
54alter table subreddit_posts
55 add constraint UK_ih17w4fa2em7w3u1tt8gqv2wh unique (posts_post_id)
56
57alter table comment
58 add constraint FKs1slvnkuemjsq2kj4h3vhx7i1
59 foreign key (post_id)
60 references post
61
62alter table comment
63 add constraint FK8kcum44fvpupyw6f5baccx25c
64 foreign key (user_id)
65 references user
66
67alter table post
68 add constraint FK7dhm40vytolqggids4vc9ykvt
69 foreign key (id)
70 references subreddit
71
72alter table post
73 add constraint FK72mt33dhhs48hf9gcqrq4fxte
74 foreign key (user_id)
75 references user
76
77alter table subreddit
78 add constraint FKqye4s0ll7xwj74d7irovyhbvg
79 foreign key (user_user_id)
80 references user
81
82alter table subreddit_posts
83 add constraint FKl27wc8sin3rt45ayge7fanx10
84 foreign key (posts_post_id)
85 references post
86
87alter table subreddit_posts
88 add constraint FK1plpyiqs72shw84g90q0fes5r
89 foreign key (subreddit_id)
90 references subreddit
91
92alter table vote
93 add constraint FKl3c067ewaw5xktl5cjvniv3e9
94 foreign key (post_id)
95 references post
96
97alter table vote
98 add constraint FKcsaksoe2iepaj8birrmithwve
99 foreign key (user_id)
100 references user
101