"""Drop legacy collected_data columns after metadata backfill verification.""" from __future__ import annotations import asyncio import sys from pathlib import Path from sqlalchemy import text ROOT = Path(__file__).resolve().parents[1] BACKEND_DIR = ROOT / "backend" for path in (ROOT, BACKEND_DIR): path_str = str(path) if path_str not in sys.path: sys.path.insert(0, path_str) from app.db.session import engine # noqa: E402 DROP_SQL = """ ALTER TABLE collected_data DROP COLUMN IF EXISTS country, DROP COLUMN IF EXISTS city, DROP COLUMN IF EXISTS latitude, DROP COLUMN IF EXISTS longitude, DROP COLUMN IF EXISTS value, DROP COLUMN IF EXISTS unit; """ async def main() -> None: async with engine.begin() as conn: await conn.execute(text(DROP_SQL)) print("Dropped legacy collected_data columns: country, city, latitude, longitude, value, unit.") if __name__ == "__main__": asyncio.run(main())