Automated Action 73b706f0eb Set up Solana Arbitrage Trading System
- Created Alembic migrations for SQLite database
- Set up database initialization on app startup
- Fixed linting issues with Ruff
- Updated README with comprehensive documentation
- Configured startup tasks and health checks
2025-06-05 19:34:12 +00:00

36 lines
1008 B
Python

import logging
import alembic.config
from pathlib import Path
from app.core.config import settings
logger = logging.getLogger(__name__)
def init_db():
"""Initialize the database by running migrations"""
logger.info("Initializing database")
# Create DB directory if it doesn't exist
settings.DB_DIR.mkdir(parents=True, exist_ok=True)
# Get the path to the alembic.ini file
alembic_ini_path = Path(__file__).parent.parent.parent / "alembic.ini"
if not alembic_ini_path.exists():
logger.error(f"Alembic config file not found at {alembic_ini_path}")
return
try:
# Run the migrations
alembic_args = [
'--raiseerr',
'-c', str(alembic_ini_path),
'upgrade', 'head',
]
alembic.config.main(argv=alembic_args)
logger.info("Database initialized successfully")
except Exception as e:
logger.error(f"Error initializing database: {str(e)}")
raise