jamiya / scripts /migrate.py
jameszokah's picture
Refactor migration script: streamline the database migration process by removing Alembic dependencies, updating logging for clarity, and initializing database tables directly. Enhance error handling for improved debugging during migration execution.
bd54343
raw
history blame
1.09 kB
#!/usr/bin/env python3
"""
Database migration script for the TTS API.
"""
import os
import sys
import logging
from pathlib import Path
# Set up logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def run_migrations():
"""Run database migrations."""
try:
# Log current environment
logger.info(f"Current directory: {os.getcwd()}")
logger.info(f"Python Path (sys.path): {sys.path}")
# Import the database configuration
from app.models import init_db
# Initialize database tables
init_db()
logger.info("Database tables created successfully")
return True
except ImportError as e:
logger.error(f"Error importing database configuration: {e}")
return False
except Exception as e:
logger.error(f"Error running migrations: {e}")
return False
if __name__ == "__main__":
success = run_migrations()
sys.exit(0 if success else 1)