""" Migration script to add the task_blockers association table. Run this once if you have an existing database. Usage (from inside the backend container or with the venv active): python migrate_add_blockers.py """ import sqlite3 import os db_path = os.path.join(os.path.dirname(__file__), 'bit.db') if not os.path.exists(db_path): print(f"Database not found at {db_path}") print("No migration needed — new database will be created with the correct schema.") exit(0) conn = sqlite3.connect(db_path) cursor = conn.cursor() try: # Check if the table already exists cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='task_blockers'") if cursor.fetchone(): print("Table 'task_blockers' already exists. Migration not needed.") else: cursor.execute(""" CREATE TABLE task_blockers ( task_id INTEGER NOT NULL REFERENCES tasks(id) ON DELETE CASCADE, blocked_by_id INTEGER NOT NULL REFERENCES tasks(id) ON DELETE CASCADE, PRIMARY KEY (task_id, blocked_by_id) ) """) conn.commit() print("Successfully created 'task_blockers' table.") except Exception as e: print(f"Error during migration: {e}") conn.rollback() finally: conn.close()