fix: improve sql queries
This commit is contained in:
@@ -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)`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user