fix: improve sql queries

This commit is contained in:
2026-04-09 04:48:50 +04:00
parent 89f0856a04
commit 91ca996e74
10 changed files with 495 additions and 219 deletions
+11
View File
@@ -243,6 +243,17 @@ export async function migrate(sql: any) {
`;
await sql`CREATE INDEX IF NOT EXISTS idx_uptime_rollup_lookup ON monitor_uptime_rollup(monitor_id, bucket_type, bucket_start DESC)`;
// Watermark table for the rollup job. Each row records the most recent
// pings.checked_at that has been folded into a given bucket_type's rollup
// rows. Lets the periodic rollup pass scan only NEW pings since the last
// pass instead of re-aggregating the entire current bucket on every tick.
await sql`
CREATE TABLE IF NOT EXISTS rollup_watermarks (
bucket_type TEXT PRIMARY KEY,
last_aggregated_at TIMESTAMPTZ NOT NULL DEFAULT to_timestamp(0)
)
`;
await sql`CREATE INDEX IF NOT EXISTS idx_pings_monitor ON pings(monitor_id, checked_at DESC)`;
await sql`CREATE INDEX IF NOT EXISTS idx_pings_checked_at ON pings(checked_at)`;