2021-09-11 00:00:04 +02:00
|
|
|
package sql
|
|
|
|
|
|
|
|
func (s *Store) createPostgresSchema() error {
|
|
|
|
_, err := s.db.Exec(`
|
2021-10-23 22:47:12 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS endpoints (
|
|
|
|
endpoint_id BIGSERIAL PRIMARY KEY,
|
|
|
|
endpoint_key TEXT UNIQUE,
|
2022-09-08 00:17:28 +02:00
|
|
|
endpoint_name TEXT NOT NULL,
|
|
|
|
endpoint_group TEXT NOT NULL,
|
2021-10-23 22:47:12 +02:00
|
|
|
UNIQUE(endpoint_name, endpoint_group)
|
2021-09-11 00:00:04 +02:00
|
|
|
)
|
|
|
|
`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = s.db.Exec(`
|
2021-10-23 22:47:12 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS endpoint_events (
|
|
|
|
endpoint_event_id BIGSERIAL PRIMARY KEY,
|
2022-09-08 00:17:28 +02:00
|
|
|
endpoint_id INTEGER NOT NULL REFERENCES endpoints(endpoint_id) ON DELETE CASCADE,
|
|
|
|
event_type TEXT NOT NULL,
|
|
|
|
event_timestamp TIMESTAMP NOT NULL
|
2021-09-11 00:00:04 +02:00
|
|
|
)
|
|
|
|
`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = s.db.Exec(`
|
2021-10-23 22:47:12 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS endpoint_results (
|
|
|
|
endpoint_result_id BIGSERIAL PRIMARY KEY,
|
2022-09-08 00:17:28 +02:00
|
|
|
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
|
2021-09-11 00:00:04 +02:00
|
|
|
)
|
|
|
|
`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = s.db.Exec(`
|
2021-10-23 22:47:12 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS endpoint_result_conditions (
|
|
|
|
endpoint_result_condition_id BIGSERIAL PRIMARY KEY,
|
2022-09-08 00:17:28 +02:00
|
|
|
endpoint_result_id BIGINT NOT NULL REFERENCES endpoint_results(endpoint_result_id) ON DELETE CASCADE,
|
|
|
|
condition TEXT NOT NULL,
|
|
|
|
success BOOLEAN NOT NULL
|
2021-09-11 00:00:04 +02:00
|
|
|
)
|
|
|
|
`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = s.db.Exec(`
|
2021-10-23 22:47:12 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS endpoint_uptimes (
|
|
|
|
endpoint_uptime_id BIGSERIAL PRIMARY KEY,
|
2022-09-08 00:17:28 +02:00
|
|
|
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,
|
2021-10-23 22:47:12 +02:00
|
|
|
UNIQUE(endpoint_id, hour_unix_timestamp)
|
2021-09-11 00:00:04 +02:00
|
|
|
)
|
|
|
|
`)
|
2022-09-07 03:22:02 +02:00
|
|
|
// Silent table modifications
|
2022-09-08 00:17:28 +02:00
|
|
|
_, _ = s.db.Exec(`ALTER TABLE endpoint_results ADD IF NOT EXISTS domain_expiration BIGINT NOT NULL DEFAULT 0`)
|
2021-09-11 00:00:04 +02:00
|
|
|
return err
|
|
|
|
}
|