fix(db): declare locale on CommandConfig model + defensive migration
Release / release (push) Successful in 1m7s

Startup was crashing on fresh databases because:
- init_db() calls SQLModel.metadata.create_all(), which builds tables
  from the model classes. CommandConfig didn't declare `locale`, so
  the created command_config table lacked the column.
- The seeder then issued INSERTs that included locale='en', causing
  `OperationalError: table command_config has no column named locale`.

The legacy migration #6 in migrate_schema creates command_config WITH
locale via raw SQL, so upgraded databases worked. Only fresh installs
broke.

Fix:
- Add `locale: str = Field(default='en')` to CommandConfig model so
  create_all() produces a consistent schema.
- Add a defensive ALTER TABLE ... ADD COLUMN locale in migrate_schema's
  else-branch, so any existing command_config table missing the column
  (from a broken v0.1.0 install) is backfilled on next startup.
This commit is contained in:
2026-04-21 20:35:21 +03:00
parent f27fa42b87
commit 293614d667
2 changed files with 8 additions and 0 deletions
@@ -614,6 +614,13 @@ async def migrate_entity_refactor(engine: AsyncEngine) -> None:
")"
))
logger.info("Created command_config table")
else:
# Backfill locale column for tables created before locale was on the model
if not await _has_column(conn, "command_config", "locale"):
await conn.execute(
text("ALTER TABLE command_config ADD COLUMN locale TEXT DEFAULT 'en'")
)
logger.info("Added locale column to command_config table")
# ------------------------------------------------------------------
# 7. Create command_tracker table