
- Updated migrations/env.py to handle Python import paths correctly - Fixed app/db/base.py to import all required models - Updated database path in app/db/session.py to work in both local and container environments - Updated SQLite path in alembic.ini for container compatibility
28 lines
805 B
Python
28 lines
805 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
|
|
|
|
# Check if we're running in the container environment
|
|
IN_CONTAINER = os.path.exists('/app/repo')
|
|
|
|
# Create the directory for the database if it doesn't exist
|
|
if IN_CONTAINER:
|
|
# Container path
|
|
DB_DIR = Path("/app") / "repo" / "storage" / "db"
|
|
else:
|
|
# Local development path
|
|
DB_DIR = Path("/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)
|
|
|
|
Base = declarative_base() |