-
Notifications
You must be signed in to change notification settings - Fork 18
/
schema.sql
248 lines (218 loc) · 5.62 KB
/
schema.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
create table meta(
id integer primary key,
name text not null unique,
value text not null
);
insert into
meta(name, value)
values
('setup', 'domain');
create table user(
id integer primary key,
username text not null unique,
password text not null
);
create table user_invitation(
id integer primary key,
token text not null unique,
created_at datetime not null
);
create table session(
id integer primary key,
token text not null unique,
csrf_token text not null unique,
user_id int references user(id) on delete cascade not null
);
create table service(
id integer primary key,
slug text not null unique,
name text not null,
helper_text text not null
);
create table severity(severity text not null);
insert into
severity(severity)
values
('blue');
create table alert(
id integer primary key,
title text not null,
type text not null,
severity text not null,
created_at datetime not null,
ended_at datetime
);
create table alert_message(
id integer primary key,
content text not null,
created_at datetime not null,
last_updated_at datetime,
alert_id int references alert(id) on delete cascade not null
);
create table alert_subscription(
id integer primary key,
type text not null,
destination text not null collate nocase,
meta text,
active int not null default true,
unique(type, destination)
);
create table alert_notification(
id integer primary key,
created_at datetime not null,
sent_at datetime,
alert_subscription_id int references alert_subscription(id) on delete cascade not null,
alert_message_id int references alert_message(id) on delete cascade not null
);
create table alert_setting(
id integer primary key,
name text not null unique,
value text not null
);
create table pending_email_alert_subscription(
id integer primary key,
token string not null,
email text not null collate nocase,
created_at datetime not null,
confirmed_at datetime
);
create table alert_service(
id integer primary key,
alert_id int references alert(id) on delete cascade not null,
service_id int references service(id) on delete cascade not null
);
create table monitor(
id integer primary key,
slug text not null unique,
name text not null,
url text not null,
method text not null,
frequency integer not null,
timeout integer not null,
attempts integer not null,
request_headers text,
body_format text,
body text
);
create table monitor_log(
id integer primary key,
started_at datetime not null,
ended_at datetime not null,
response_code integer,
error_message text,
attempts integer not null,
result text not null,
monitor_id int references monitor(id) on delete cascade not null
);
create index idx_monitor_log_monitor_id_started_at on monitor_log(monitor_id, started_at);
create table monitor_log_last_checked(
id integer primary key,
checked_at datetime not null,
monitor_id int int references monitor(id) on delete cascade not null unique,
monitor_log_id int references monitor_log(id) on delete cascade not null unique
);
create table notification_channel(
id integer primary key,
slug text not null unique,
name text not null,
type text not null check(type in ('smtp', 'slack')),
details text not null
);
create table monitor_notification_channel(
id integer primary key,
monitor_id int references monitor(id) on delete cascade not null,
notification_channel_id int references notification_channel(id) on delete cascade not null,
unique(monitor_id, notification_channel_id)
);
create table alert_setting_smtp_notification(
id integer primary key,
notification_channel_id int references notification_channel(id) on delete cascade not null unique
);
create table mail_group(
id integer primary key,
slug text not null unique,
name text not null,
description text
);
create table mail_group_member(
id integer primary key,
email_address text not null collate nocase,
mail_group_id int references mail_group(id) on delete cascade not null,
unique(mail_group_id, email_address)
);
create table mail_group_monitor(
id integer primary key,
mail_group_id int references mail_group(id) on delete cascade not null,
monitor_id int references monitor(id) on delete cascade not null,
unique(mail_group_id, monitor_id)
);
create table migration(
id integer primary key,
name text not null unique,
skipped int not null
);
insert into
service(slug, name, helper_text)
values
(
'website',
'Website',
'Edit or delete this service in the admin area'
);
insert into
alert(title, type, severity, created_at)
values
(
'You''ve successfully deployed Statusnook 🎉',
'maintenance',
'',
datetime()
);
insert into
alert_service(alert_id, service_id)
select
(
select
id
from
alert
order by
id desc
limit
1
), (
select
id
from
service
order by
id desc
limit
1
);
insert into
alert_message(
content,
created_at,
alert_id
)
select
'Go ahead and delete this alert in the admin area',
datetime(),
(
select
id
from
alert
order by
id desc
limit
1
);
insert into
alert_setting(name, value)
values
(
'managed-subscriptions',
true
);