-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.sql
163 lines (142 loc) · 4.8 KB
/
models.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
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE IF NOT EXISTS services (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
link TEXT NOT NULL,
slug TEXT NOT NULL,
provider_type TEXT NOT NULL,
should_scrap_website boolean NOT NULL,
incident_url TEXT NOT NULL,
schedule_maintenance_url TEXT NOT NULL,
components_url TEXT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
deleted_at TIMESTAMPTZ
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_services_slug ON services (slug);
CREATE TABLE IF NOT EXISTS components (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
service_id INT NOT NULL,
provider_id TEXT NOT NULL,
created_at TIMESTAMPTZ NULL DEFAULT now(),
updated_at TIMESTAMPTZ NULL DEFAULT now(),
deleted_at TIMESTAMPTZ,
CONSTRAINT fk_service_id_components
FOREIGN KEY(service_id)
REFERENCES services(id)
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_components_provider_id_service_id ON components (service_id, provider_id);
CREATE TABLE IF NOT EXISTS incidents (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
link TEXT NOT NULL,
provider_impact TEXT,
impact TEXT,
service_id INT NOT NULL,
provider_id TEXT NOT NULL,
provider_created_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ,
CONSTRAINT fk_service_id_incidents
FOREIGN KEY(service_id)
REFERENCES services(id)
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_provider_id ON incidents(provider_id);
CREATE TABLE IF NOT EXISTS incident_updates (
id SERIAL PRIMARY KEY,
incident_id INT NOT NULL,
description TEXT NOT NULL,
provider_status TEXT NOT NULL,
status TEXT NOT NULL,
status_time TIMESTAMPTZ NOT NULL,
provider_id TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ,
CONSTRAINT fk_incident_id_incident_updates
FOREIGN KEY (incident_id)
REFERENCES incidents(id)
);
CREATE TABLE IF NOT EXISTS incident_components (
id SERIAL PRIMARY KEY,
incident_id INT NOT NULL,
component_id INT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ,
CONSTRAINT fk_incident_components_incident_id
FOREIGN KEY (incident_id)
REFERENCES incidents(id),
CONSTRAINT fk_incident_components_component_id
FOREIGN KEY (component_id)
REFERENCES components(id)
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_incident_id_component_id ON incident_components(incident_id, component_id);
CREATE TABLE IF NOT EXISTS subscriptions (
id SERIAL PRIMARY KEY,
uuid UUID DEFAULT (uuid_generate_v4()),
service_id INT NOT NULL,
is_all_components BOOLEAN NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ,
CONSTRAINT fk_subscriptions_service_id
FOREIGN KEY (service_id)
REFERENCES services(id)
);
CREATE TABLE IF NOT EXISTS subscription_components (
id SERIAL PRIMARY KEY,
subscription_id INT NOT NULL,
component_id INT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ,
CONSTRAINT fk_subscriptions_component_id
FOREIGN KEY (component_id)
REFERENCES components(id),
CONSTRAINT fk_subscription_components_subscription_id
FOREIGN KEY (subscription_id)
REFERENCES subscriptions(id)
ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS squadcast_extensions (
id SERIAL PRIMARY KEY,
uuid UUID NOT NULL DEFAULT (uuid_generate_v4()),
webhook_url TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_squadcast_extension_uuid ON squadcast_extensions(uuid);
CREATE TABLE IF NOT EXISTS pagerduty_extensions (
id SERIAL PRIMARY KEY,
uuid UUID NOT NULL DEFAULT (uuid_generate_v4()),
routing_key TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_pagerduty_extension_uuid ON pagerduty_extensions(uuid);
CREATE TABLE IF NOT EXISTS chatops_extensions (
id SERIAL PRIMARY KEY,
uuid UUID NOT NULL DEFAULT (uuid_generate_v4()),
-- type - slack, msteams, discord
type TEXT NOT NULL,
webhook_url TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_chatops_extension_uuid ON chatops_extensions(uuid);
CREATE TABLE IF NOT EXISTS webhook_extensions (
id SERIAL PRIMARY KEY,
uuid UUID NOT NULL DEFAULT (uuid_generate_v4()),
webhook_url TEXT NOT NULL,
secret TEXT,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_webhooks_extension_uuid ON webhook_extensions(uuid);