-
-
Notifications
You must be signed in to change notification settings - Fork 389
/
specific_postgres.go
85 lines (84 loc) · 2.88 KB
/
specific_postgres.go
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
package sql
func (s *Store) createPostgresSchema() error {
_, err := s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoints (
endpoint_id BIGSERIAL PRIMARY KEY,
endpoint_key TEXT UNIQUE,
endpoint_name TEXT NOT NULL,
endpoint_group TEXT NOT NULL,
UNIQUE(endpoint_name, endpoint_group)
)
`)
if err != nil {
return err
}
_, err = s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoint_events (
endpoint_event_id BIGSERIAL PRIMARY KEY,
endpoint_id BIGINT NOT NULL REFERENCES endpoints(endpoint_id) ON DELETE CASCADE,
event_type TEXT NOT NULL,
event_timestamp TIMESTAMP NOT NULL
)
`)
if err != nil {
return err
}
_, err = s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoint_results (
endpoint_result_id BIGSERIAL PRIMARY KEY,
endpoint_id BIGINT NOT NULL REFERENCES endpoints(endpoint_id) ON DELETE CASCADE,
success BOOLEAN NOT NULL,
errors TEXT NOT NULL,
connected BOOLEAN NOT NULL,
status BIGINT NOT NULL,
dns_rcode TEXT NOT NULL,
certificate_expiration BIGINT NOT NULL,
domain_expiration BIGINT NOT NULL,
hostname TEXT NOT NULL,
ip TEXT NOT NULL,
duration BIGINT NOT NULL,
timestamp TIMESTAMP NOT NULL
)
`)
if err != nil {
return err
}
_, err = s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoint_result_conditions (
endpoint_result_condition_id BIGSERIAL PRIMARY KEY,
endpoint_result_id BIGINT NOT NULL REFERENCES endpoint_results(endpoint_result_id) ON DELETE CASCADE,
condition TEXT NOT NULL,
success BOOLEAN NOT NULL
)
`)
if err != nil {
return err
}
_, err = s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoint_uptimes (
endpoint_uptime_id BIGSERIAL PRIMARY KEY,
endpoint_id BIGINT NOT NULL REFERENCES endpoints(endpoint_id) ON DELETE CASCADE,
hour_unix_timestamp BIGINT NOT NULL,
total_executions BIGINT NOT NULL,
successful_executions BIGINT NOT NULL,
total_response_time BIGINT NOT NULL,
UNIQUE(endpoint_id, hour_unix_timestamp)
)
`)
if err != nil {
return err
}
_, err = s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoint_alerts_triggered (
endpoint_alert_trigger_id BIGSERIAL PRIMARY KEY,
endpoint_id BIGINT NOT NULL REFERENCES endpoints(endpoint_id) ON DELETE CASCADE,
configuration_checksum TEXT NOT NULL,
resolve_key TEXT NOT NULL,
number_of_successes_in_a_row INTEGER NOT NULL,
UNIQUE(endpoint_id, configuration_checksum)
)
`)
// Silent table modifications TODO: Remove this in v6.0.0
_, _ = s.db.Exec(`ALTER TABLE endpoint_results ADD IF NOT EXISTS domain_expiration BIGINT NOT NULL DEFAULT 0`)
return err
}