Fix init_db: move household_id index after migration ALTER TABLE
This commit is contained in:
@@ -62,14 +62,13 @@ def init_db() -> None:
|
||||
ON responses(period_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_meal_periods_date
|
||||
ON meal_periods(date);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_household
|
||||
ON users(household_id);
|
||||
""")
|
||||
|
||||
# Migration: if users table exists but lacks household_id column, add it.
|
||||
cols = [r["name"] for r in db.execute("PRAGMA table_info(users)").fetchall()]
|
||||
if "household_id" not in cols:
|
||||
db.execute("ALTER TABLE users ADD COLUMN household_id INTEGER REFERENCES households(id)")
|
||||
db.execute("CREATE INDEX IF NOT EXISTS idx_users_household ON users(household_id)")
|
||||
|
||||
|
||||
# ── Households ────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user