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()); }