-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatesql
More file actions
75 lines (66 loc) · 1.63 KB
/
createsql
File metadata and controls
75 lines (66 loc) · 1.63 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Tables schema
# --- !Ups
CREATE TABLE public.Likes
(
tweet_id integer,
liker_id integer,
post_owner_id integer,
date date
);
CREATE TABLE public.Trends
(
id integer SERIAL PRIMARY KEY,
date date,
type character(1),
link character varying,
ranking integer,
);
CREATE TABLE public.Hashtag_Tweet_Relation
(
tweet_id integer,
hashtag_id integer
);
CREATE TABLE public.Location
(
Location_id integer NOT NULL P,
name character varying,
CONSTRAINT location_id PRIMARY KEY (Location_id)
);
CREATE TABLE public.Accounts
(
account_id SERIAL PRIMARY KEY,
total_likes integer,
username character varying,
password character varying,
FOREIGN KEY (account_id) REFERENCES public.Tweets (tweet_owner) ON DELETE CASCADE,
FOREIGN KEY (account_id) REFERENCES public.Likes (liker_id) ON DELETE CASCADE
);
CREATE TABLE public.Hashtags
(
hashtag_id integer NOT NULL,
created_date date,
CONSTRAINT hashtag_id PRIMARY KEY (hashtag_id)
REFERENCES public.Hashtag_Tweet_Relation (hashtag_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE public.Tweets
(
tweet_id integer,
tweet_owner character varying,
tweet_owner_id integer
tweet_text character varying,
total_likes integer,
location_id integer,
CONSTRAINT tweet_id PRIMARY KEY (tweet_id),
CONSTRAINT tweet_owner FOREIGN KEY (tweet_owner)
REFERENCES public.Accounts (account_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE
);
# --- !Downs
DROP TABLE public.Likes;
DROP TABLE public.Trends;
DROP TABLE public.Hashtag_Tweet_Relation;
DROP TABLE public.Location;
DROP TABLE public.Accounts;
DROP TABLE public.Hashtags;
DROP TABLE public.Tweets;