Spaces:
Running
Running
| import sqlite3 | |
| import os | |
| DB_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "musical_master.db") | |
| def migrate(): | |
| conn = sqlite3.connect(DB_PATH) | |
| cursor = conn.cursor() | |
| # 1. Update groups table | |
| cursor.execute("PRAGMA table_info(groups)") | |
| columns = [row[1] for row in cursor.fetchall()] | |
| print(f"Columnas en 'groups': {columns}") | |
| if "codigo" not in columns: | |
| cursor.execute("ALTER TABLE groups ADD COLUMN codigo TEXT DEFAULT NULL") | |
| print("[OK] Columna 'codigo' agregada a 'groups'.") | |
| else: | |
| print("[INFO] Columna 'codigo' ya existe en 'groups'.") | |
| # 2. Update tasks table | |
| cursor.execute("PRAGMA table_info(tasks)") | |
| tasks_columns = [row[1] for row in cursor.fetchall()] | |
| print(f"Columnas en 'tasks': {tasks_columns}") | |
| if "group_id" not in tasks_columns: | |
| cursor.execute("ALTER TABLE tasks ADD COLUMN group_id INTEGER DEFAULT NULL") | |
| print("[OK] Columna 'group_id' agregada a 'tasks'.") | |
| else: | |
| print("[INFO] Columna 'group_id' ya existe en 'tasks'.") | |
| conn.commit() | |
| conn.close() | |
| print("[OK] Migracion de grupos completada.") | |
| if __name__ == "__main__": | |
| migrate() | |