Automated Action a9c71e9245 Fix database migration path issues for development environment
- Added proper path handling to alembic env.py
- Updated database path to use relative paths in development
- Created necessary storage directories
- Updated alembic configuration to use dynamic SQLAlchemy URL

generated with BackendIM... (backend.im)
2025-05-13 23:25:51 +00:00

25 lines
676 B
Python

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from pathlib import Path
import os
# Use relative path for development environment
BASE_DIR = Path(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
DB_DIR = BASE_DIR / "app" / "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)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()