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 <noreply@anthropic.com>
This commit is contained in:
11
lib/db.ts
11
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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user