fix: make ALTER TABLE migrations idempotent with IF NOT EXISTS
SQLite's executescript() auto-commits each DDL statement, so a partial migration failure leaves columns in the DB without marking the migration done. On the next startup the runner retries and hits duplicate column errors. Use ADD COLUMN IF NOT EXISTS (SQLite 3.35+, shipped in Python 3.11+) so migrations 004 and 005 are safe to re-run in any partial state.
This commit is contained in:
parent
81e41e39ab
commit
59f728cba0
2 changed files with 7 additions and 5 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
-- Staging DB: persistent listing tracking across searches.
|
-- Staging DB: persistent listing tracking across searches.
|
||||||
-- Adds temporal metadata to listings so we can detect stale/repriced/recurring items.
|
-- Adds temporal metadata to listings so we can detect stale/repriced/recurring items.
|
||||||
|
|
||||||
-- first_seen_at already defined in 001_init.sql CREATE TABLE; skip to avoid duplicate column error on fresh installs
|
-- IF NOT EXISTS (SQLite 3.35+, Python 3.11 ships 3.39+) makes this safe to re-run
|
||||||
ALTER TABLE listings ADD COLUMN last_seen_at TEXT;
|
-- in any state: fresh install, partial-failure recovery, or already-applied.
|
||||||
ALTER TABLE listings ADD COLUMN times_seen INTEGER NOT NULL DEFAULT 1;
|
ALTER TABLE listings ADD COLUMN IF NOT EXISTS first_seen_at TEXT;
|
||||||
ALTER TABLE listings ADD COLUMN price_at_first_seen REAL;
|
ALTER TABLE listings ADD COLUMN IF NOT EXISTS last_seen_at TEXT;
|
||||||
|
ALTER TABLE listings ADD COLUMN IF NOT EXISTS times_seen INTEGER NOT NULL DEFAULT 1;
|
||||||
|
ALTER TABLE listings ADD COLUMN IF NOT EXISTS price_at_first_seen REAL;
|
||||||
|
|
||||||
-- Backfill existing rows so columns are non-null where we have data
|
-- Backfill existing rows so columns are non-null where we have data
|
||||||
UPDATE listings SET
|
UPDATE listings SET
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
-- Add per-listing category name, extracted from eBay API response.
|
-- Add per-listing category name, extracted from eBay API response.
|
||||||
-- Used to derive seller category_history_json without _ssn scraping.
|
-- Used to derive seller category_history_json without _ssn scraping.
|
||||||
ALTER TABLE listings ADD COLUMN category_name TEXT;
|
ALTER TABLE listings ADD COLUMN IF NOT EXISTS category_name TEXT;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue