forked from digitalocean/sample-websocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddl.sql
68 lines (47 loc) · 1.71 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
-- public.creators definition
-- Drop table
-- DROP TABLE public.creators;
CREATE TABLE public.creators (
id int4 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL,
"name" varchar NULL,
website_url varchar NULL,
CONSTRAINT creators_pk PRIMARY KEY (id)
);
-- public.dreams definition
-- Drop table
-- DROP TABLE public.dreams;
CREATE TABLE public.dreams (
url_part varchar NOT NULL,
creator_id int4 NULL,
title varchar NULL,
CONSTRAINT dreams_unique UNIQUE (url_part)
);
-- public.dreams foreign keys
ALTER TABLE public.dreams ADD CONSTRAINT dreams_creators_fk FOREIGN KEY (creator_id) REFERENCES public.creators(id);
-- public.users definition
-- Drop table
-- DROP TABLE public.users;
CREATE TABLE public.users (
device_uid varchar(80) NULL,
display_name varchar(80) NULL,
currency int4 NULL,
created_time timestamp DEFAULT CURRENT_TIMESTAMP NULL,
CONSTRAINT users_unique UNIQUE (device_uid)
);
-- public.events definition
-- Drop table
-- DROP TABLE public.events;
CREATE TABLE public.events (
id int4 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL,
device_uid varchar NULL,
"type" varchar NULL,
impact_key varchar NULL,
session_hash varchar NULL,
dream_url_part varchar NULL,
"timestamp" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
currency_value int4 NULL,
CONSTRAINT events_pk PRIMARY KEY (id)
);
-- public.events foreign keys
ALTER TABLE public.events ADD CONSTRAINT events_dreams_fk FOREIGN KEY (dream_url_part) REFERENCES public.dreams(url_part);
ALTER TABLE public.events ADD CONSTRAINT events_users_fk FOREIGN KEY (device_uid) REFERENCES public.users(device_uid);