Files
terra-view/backend/migrate_add_module_status.py
T
serversdown 092b72f63c feat(projects): per-module status (independent sound/vibration lifecycle)
Each ProjectModule now carries its own status (active|on_hold|completed)
so one half of a combined project can wrap up while the other keeps
running — e.g. mark Sound "completed" while Vibration stays "active",
without archiving the whole project.

- models.py: ProjectModule.status column (default 'active')
- migrate_add_module_status.py: idempotent ALTER (run on prod before deploy)
- projects.py: _get_module_statuses() helper, MODULE_STATUSES, and a
  PUT /{id}/modules/{type}/status endpoint; module_status now included in
  the project GET, header, and /list contexts so the UI can render it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015m9FuJvk65kJmmP3c9c6r1
2026-06-22 20:24:27 +00:00

55 lines
1.6 KiB
Python

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