From 20f1058e9e90cd5c9ab83739fbecac7221fc53b1 Mon Sep 17 00:00:00 2001 From: josh Date: Sat, 4 Apr 2026 12:42:03 -0400 Subject: [PATCH] fix: protect today's record from scrape overwrites Change upsertDay WHERE guard from >= to > date('now') so today is treated identically to past dates. Once a park's operating day starts the API drops that date, making it appear closed. The record written when the date was still future is the correct one and must be preserved. Only strictly future dates (> today) are now eligible for upserts. Co-Authored-By: Claude Sonnet 4.6 --- lib/db.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/db.ts b/lib/db.ts index 333a8e9..813ae3f 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -46,11 +46,12 @@ export function upsertDay( hoursLabel?: string, specialType?: string ) { - // For past dates: INSERT new rows freely, but never overwrite existing records. - // The API stops returning past dates once they've elapsed, so the DB row is the - // permanent historical truth — we must not let a future scrape clobber it. + // Today and past dates: INSERT new rows freely, but NEVER overwrite existing records. + // Once an operating day begins the API drops that date from its response, so a + // re-scrape would incorrectly record the day as closed. The DB row written when + // the date was still in the future is the permanent truth for that day. // - // For today and future dates: full upsert — the schedule can still change. + // Future dates only: full upsert — hours can change and closures can be added. db.prepare(` INSERT INTO park_days (park_id, date, is_open, hours_label, special_type, scraped_at) VALUES (?, ?, ?, ?, ?, ?) @@ -59,7 +60,7 @@ export function upsertDay( hours_label = excluded.hours_label, special_type = excluded.special_type, scraped_at = excluded.scraped_at - WHERE park_days.date >= date('now') + WHERE park_days.date > date('now') `).run(parkId, date, isOpen ? 1 : 0, hoursLabel ?? null, specialType ?? null, new Date().toISOString()); }