42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
"""
|
|
Migration: add report_date to monitoring_sessions.
|
|
|
|
Run once:
|
|
python backend/migrate_add_session_report_date.py
|
|
|
|
Or inside the container:
|
|
docker exec terra-view-terra-view-1 python3 backend/migrate_add_session_report_date.py
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from backend.database import engine
|
|
from sqlalchemy import text
|
|
|
|
def run():
|
|
with engine.connect() as conn:
|
|
# Check which columns already exist
|
|
result = conn.execute(text("PRAGMA table_info(monitoring_sessions)"))
|
|
existing = {row[1] for row in result}
|
|
|
|
added = []
|
|
for col, definition in [
|
|
("report_date", "DATE"),
|
|
]:
|
|
if col not in existing:
|
|
conn.execute(text(f"ALTER TABLE monitoring_sessions ADD COLUMN {col} {definition}"))
|
|
added.append(col)
|
|
else:
|
|
print(f" Column '{col}' already exists — skipping.")
|
|
|
|
conn.commit()
|
|
|
|
if added:
|
|
print(f" Added columns: {', '.join(added)}")
|
|
print("Migration complete.")
|
|
|
|
if __name__ == "__main__":
|
|
run()
|