File size: 1,877 Bytes
d69447e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
"""
Migration: Create drivers table
Created: 2025-11-14
"""
import sys
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from database.connection import get_db_connection
from database.schema import DRIVERS_SCHEMA
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def up():
"""Apply migration - Create drivers table"""
logger.info("Starting migration: Create drivers table")
try:
conn = get_db_connection()
cursor = conn.cursor()
# Execute drivers schema
logger.info("Creating drivers table...")
cursor.execute(DRIVERS_SCHEMA)
conn.commit()
cursor.close()
conn.close()
logger.info("β
Migration completed successfully: Drivers table created")
return True
except Exception as e:
logger.error(f"β Migration failed: {e}")
if conn:
conn.rollback()
return False
def down():
"""Rollback migration - Drop drivers table"""
logger.info("Rolling back migration: Drop drivers table")
try:
conn = get_db_connection()
cursor = conn.cursor()
logger.info("Dropping drivers table...")
cursor.execute("DROP TABLE IF EXISTS drivers CASCADE;")
conn.commit()
cursor.close()
conn.close()
logger.info("β
Rollback completed successfully: Drivers table dropped")
return True
except Exception as e:
logger.error(f"β Rollback failed: {e}")
if conn:
conn.rollback()
return False
if __name__ == "__main__":
import sys
if len(sys.argv) > 1 and sys.argv[1] == "down":
# Rollback
success = down()
else:
# Apply migration
success = up()
sys.exit(0 if success else 1)
|