Automated Action b6561799a2 Fix Alembic migration error and database path resolution
- Fix 'No module named app' error by adding project root to Python path
- Ensure consistent database path between app and migrations
- Update database configuration to work in both development and deployment
- Set appropriate SQLite dialect configuration with render_as_batch
- Update documentation with additional migration instructions
- Fix imports order to comply with linting standards
2025-05-17 21:06:06 +00:00

25 lines
725 B
Python

from pathlib import Path
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# Get the project root directory
BASE_DIR = Path(__file__).resolve().parent.parent.parent
# Ensure this works in both development and deployment environments
if os.path.exists("/app"):
# Docker/deployment environment
DB_DIR = Path("/app/storage/db")
else:
# Development environment
DB_DIR = BASE_DIR / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
engine = create_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)