""" Migration: add a per-module `status` column to `project_modules`. A combined project (sound + vibration) often finishes one kind of work before the other. Rather than archiving the whole project, each module now carries its own lifecycle so e.g. the sound side can read "Completed" while vibration stays "Active". Behavior: - status = 'active' → module is live (default for all existing rows) - status = 'on_hold' → paused; data/tabs stay visible - status = 'completed' → wrapped up; surfaced as a done badge Idempotent — safe to re-run. Non-destructive — adds only. Run with: docker exec terra-view-terra-view-1 python3 /app/backend/migrate_add_module_status.py """ import os import sqlite3 DB_PATH = "./data/seismo_fleet.db" def _has_column(cur: sqlite3.Cursor, table: str, column: str) -> bool: cur.execute(f"PRAGMA table_info({table})") return any(row[1] == column for row in cur.fetchall()) def migrate_database() -> None: if not os.path.exists(DB_PATH): print(f"Database not found at {DB_PATH}") return conn = sqlite3.connect(DB_PATH) cur = conn.cursor() if not _has_column(cur, "project_modules", "status"): cur.execute( "ALTER TABLE project_modules ADD COLUMN status TEXT NOT NULL DEFAULT 'active'" ) conn.commit() print(" Added column project_modules.status (default 'active').") else: print(" project_modules already has status — nothing to do.") conn.close() if __name__ == "__main__": print("Running migration: add status to project_modules") migrate_database() print("Done.")