Files
planet/scripts/drop_collected_data_legacy_columns.py
2026-03-25 17:19:10 +08:00

42 lines
967 B
Python

"""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())