-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.sql
85 lines (77 loc) · 2.08 KB
/
init.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
-- Sequence for users
CREATE SEQUENCE public.users_user_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- Sequence for uris
CREATE SEQUENCE public.uris_uri_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- Sequence for monitors
CREATE SEQUENCE public.monitors_monitor_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- Sequence for stats
CREATE SEQUENCE public.stats_stats_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- Table: uris
CREATE TABLE public.uris (
uri_id integer NOT NULL DEFAULT nextval('public.uris_uri_id_seq'::regclass),
uri text NOT NULL,
PRIMARY KEY (uri_id)
);
-- Table: users
CREATE TABLE public.users (
user_id integer NOT NULL DEFAULT nextval('public.users_user_id_seq'::regclass),
username character varying(32) NOT NULL,
password character varying(255) NOT NULL,
uri_id integer NOT NULL,
PRIMARY KEY (user_id),
UNIQUE (username),
FOREIGN KEY (uri_id) REFERENCES public.uris(uri_id)
);
-- Table: monitors
CREATE TABLE public.monitors (
monitor_id integer NOT NULL DEFAULT nextval('public.monitors_monitor_id_seq'::regclass),
type character varying(16) NOT NULL,
user_id integer NOT NULL,
parameters json,
PRIMARY KEY (monitor_id),
FOREIGN KEY (user_id) REFERENCES public.users(user_id)
);
-- Table: alerts
CREATE TABLE public.alerts (
alert_id uuid NOT NULL,
user_id integer,
alert_obj json NOT NULL,
PRIMARY KEY (alert_id),
FOREIGN KEY (user_id) REFERENCES public.users(user_id)
);
-- Table: stats
CREATE TABLE public.stats (
stats_id integer NOT NULL DEFAULT nextval('public.stats_stats_id_seq'::regclass),
monitor_id integer,
table_name character varying(255),
num_rows integer,
stats_obj json,
starting timestamp with time zone,
ending timestamp with time zone,
PRIMARY KEY (stats_id),
FOREIGN KEY (monitor_id) REFERENCES public.monitors(monitor_id)
);