mirror of
https://github.com/dcarrillo/atalaya.git
synced 2026-04-18 02:24:05 +00:00
30
migrations/0001_initial.sql
Normal file
30
migrations/0001_initial.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
CREATE TABLE check_results (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
monitor_name TEXT NOT NULL,
|
||||
checked_at INTEGER NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
response_time_ms INTEGER,
|
||||
error_message TEXT,
|
||||
attempts INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX idx_results_monitor_time ON check_results(monitor_name, checked_at DESC);
|
||||
|
||||
CREATE TABLE monitor_state (
|
||||
monitor_name TEXT PRIMARY KEY,
|
||||
current_status TEXT NOT NULL,
|
||||
consecutive_failures INTEGER DEFAULT 0,
|
||||
last_status_change INTEGER,
|
||||
last_checked INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE alerts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
monitor_name TEXT NOT NULL,
|
||||
alert_type TEXT NOT NULL,
|
||||
sent_at INTEGER NOT NULL,
|
||||
alert_name TEXT NOT NULL,
|
||||
success INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX idx_alerts_monitor ON alerts(monitor_name, sent_at DESC);
|
||||
14
migrations/0002_aggregation.sql
Normal file
14
migrations/0002_aggregation.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Hourly aggregated check results for data retention
|
||||
CREATE TABLE check_results_hourly (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
monitor_name TEXT NOT NULL,
|
||||
hour_timestamp INTEGER NOT NULL,
|
||||
total_checks INTEGER NOT NULL,
|
||||
successful_checks INTEGER NOT NULL,
|
||||
failed_checks INTEGER NOT NULL,
|
||||
avg_response_time_ms INTEGER,
|
||||
min_response_time_ms INTEGER,
|
||||
max_response_time_ms INTEGER
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_hourly_monitor_hour ON check_results_hourly(monitor_name, hour_timestamp);
|
||||
7
migrations/0003_indexes.sql
Normal file
7
migrations/0003_indexes.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
-- Indexes for status page & aggregation performance
|
||||
CREATE INDEX idx_checked_at ON check_results(checked_at);
|
||||
CREATE INDEX idx_hourly_timestamp ON check_results_hourly(hour_timestamp);
|
||||
|
||||
-- Optional covering index for aggregation queries
|
||||
-- Includes all columns needed for hourly aggregation to avoid table lookups
|
||||
CREATE INDEX idx_checked_at_monitor_covering ON check_results(checked_at, monitor_name, status, response_time_ms);
|
||||
Reference in New Issue
Block a user