From 3beca1ca2f47a2ac4dbbfa2573dbc739ef3934b8 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 3 Aug 2026 02:12:44 +0000 Subject: [PATCH] Add missing schema migrations for timezone columns Existing databases (from pre-July-5 installs) were missing: - users.timezone (v4.2) - nutrition_goals.diet_style and timezone_str (v4.3) create_all only adds these to brand-new databases. The migration system now detects and adds them on startup, matching the pattern used for all other schema additions. --- diligence/main.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/diligence/main.py b/diligence/main.py index ee88768..b7f6979 100644 --- a/diligence/main.py +++ b/diligence/main.py @@ -218,6 +218,24 @@ async def run_migrations(): "ALTER TABLE users ADD COLUMN is_admin BOOLEAN DEFAULT FALSE" )) + # v4.2: Add timezone to users + if "users" in tables and "timezone" not in columns.get("users", []): + await conn.execute(text( + "ALTER TABLE users ADD COLUMN timezone VARCHAR(50) DEFAULT 'UTC'" + )) + + # v4.3: Add diet_style and timezone_str to nutrition_goals + if "nutrition_goals" in tables: + ng_cols = columns.get("nutrition_goals", []) + if "diet_style" not in ng_cols: + await conn.execute(text( + "ALTER TABLE nutrition_goals ADD COLUMN diet_style VARCHAR(30) DEFAULT 'strict_keto'" + )) + if "timezone_str" not in ng_cols: + await conn.execute(text( + "ALTER TABLE nutrition_goals ADD COLUMN timezone_str VARCHAR(50) DEFAULT 'UTC'" + )) + # v4.1: Grant admin to first registered user if none exists if "users" in tables and "is_admin" in columns.get("users", []): result = await conn.execute(text(