addon
This commit is contained in:
46
backend/apply_migration_011.py
Executable file
46
backend/apply_migration_011.py
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Apply migration 011: Add fabricant and produit fields
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from app.db.session import get_peripherals_db
|
||||
|
||||
|
||||
def apply_migration():
|
||||
"""Apply migration 011"""
|
||||
db = next(get_peripherals_db())
|
||||
|
||||
try:
|
||||
print("\ud83d\udd27 Applying migration 011: Add fabricant and produit")
|
||||
print("=" * 60)
|
||||
|
||||
migration_file = Path(__file__).parent / "migrations" / "011_add_fabricant_produit.sql"
|
||||
with open(migration_file, "r") as f:
|
||||
sql_commands = f.read()
|
||||
|
||||
for command in sql_commands.split(';'):
|
||||
command = command.strip()
|
||||
if command and not command.startswith('--'):
|
||||
db.execute(command)
|
||||
|
||||
db.commit()
|
||||
print("\n\u2705 Migration 011 applied successfully!")
|
||||
print("=" * 60)
|
||||
print("Added columns:")
|
||||
print(" - fabricant (TEXT)")
|
||||
print(" - produit (TEXT)")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\u274c Error applying migration: {e}")
|
||||
db.rollback()
|
||||
raise
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
apply_migration()
|
||||
Reference in New Issue
Block a user