Fix init_db: move household_id index after migration ALTER TABLE

This commit is contained in:
agentbox
2026-07-31 21:51:05 +00:00
parent c48cd265ca
commit a318b577cb
+1 -2
View File
@@ -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 ────────────────────────────────────────────────────────────────