fix: auto-migrate SQLite schema to reconcile newly added columns on startup

This commit is contained in:
Atharv1705
2026-11-13 18:43:37 +05:30
parent d9ca4bbb02
commit 640ae9c1b4
6 changed files with 82 additions and 0 deletions
+31
View File
@@ -201,3 +201,34 @@ def test_bulk_import_templates_endpoints(client):
assert r_ins.status_code == 200
assert r_ins.headers["content-type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
assert len(r_ins.content) > 1000
def test_sqlite_auto_migration_reconciles_missing_columns():
from sqlalchemy import create_engine
from app.core.migrations import run_sqlite_migrations
test_eng = create_engine("sqlite:///:memory:")
with test_eng.begin() as conn:
# Create complaints table without assigned_team column
conn.exec_driver_sql(
"CREATE TABLE complaints ("
"id INTEGER PRIMARY KEY, "
"complaint_no VARCHAR(50), "
"asset_id INTEGER, "
"description TEXT, "
"priority VARCHAR(50), "
"registered_at DATETIME, "
"registered_by_id INTEGER, "
"received_by_id INTEGER, "
"call_status VARCHAR(50)"
")"
)
cols_before = {r[1] for r in conn.exec_driver_sql("PRAGMA table_info(complaints)").fetchall()}
assert "assigned_team" not in cols_before
# Run auto-migration
run_sqlite_migrations(test_eng)
with test_eng.begin() as conn:
cols_after = {r[1] for r in conn.exec_driver_sql("PRAGMA table_info(complaints)").fetchall()}
assert "assigned_team" in cols_after