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. Migrar tabla groups | |
| cursor.execute("PRAGMA table_info(groups)") | |
| group_cols = [row[1] for row in cursor.fetchall()] | |
| if "requiere_aprobacion" not in group_cols: | |
| cursor.execute("ALTER TABLE groups ADD COLUMN requiere_aprobacion INTEGER DEFAULT 0") | |
| print("[OK] Columna 'requiere_aprobacion' agregada a 'groups'.") | |
| else: | |
| print("[INFO] Columna 'requiere_aprobacion' ya existe en 'groups'.") | |
| # 2. Migrar tabla user_groups | |
| cursor.execute("PRAGMA table_info(user_groups)") | |
| ug_cols = [row[1] for row in cursor.fetchall()] | |
| perms = { | |
| "perm_compartir_pistas": 1, | |
| "perm_compartir_letras": 1, | |
| "perm_crud_repertorios": 0, | |
| "perm_crud_letras": 1, | |
| "perm_ver_pistas": 1, | |
| "perm_ver_letras": 1, | |
| "perm_ver_repertorios": 1, | |
| "perm_gestionar_solicitudes": 0 | |
| } | |
| for perm_col, default_val in perms.items(): | |
| if perm_col not in ug_cols: | |
| cursor.execute(f"ALTER TABLE user_groups ADD COLUMN {perm_col} INTEGER DEFAULT {default_val}") | |
| print(f"[OK] Columna '{perm_col}' agregada a 'user_groups' con DEFAULT {default_val}.") | |
| else: | |
| print(f"[INFO] Columna '{perm_col}' ya existe en 'user_groups'.") | |
| conn.commit() | |
| conn.close() | |
| print("[OK] Migracion de permisos de grupo completada exitosamente.") | |
| if __name__ == "__main__": | |
| migrate() | |