Automated Action bd33c253b2 Fix database migration and path issues
- Fix Python path in migrations/env.py for proper imports
- Update database path to use relative project paths instead of /app
- Update alembic.ini to use relative database path
- Update README with correct database location and migration instructions

generated with BackendIM... (backend.im)
2025-05-13 12:42:03 +00:00

24 lines
718 B
Python

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from pathlib import Path
import os
# Use a local path that's accessible in the current environment
DB_DIR = Path(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) / "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)
Base = declarative_base()
def init_db():
from app import models
Base.metadata.create_all(bind=engine)