from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from pathlib import Path import os # Check if we're running in the container environment at /app/repo IN_CONTAINER = os.path.exists('/app/repo') # Set the database directory path based on the environment if IN_CONTAINER: # Container path DB_DIR = Path("/app/repo/storage/db") else: # Local development path - using either the project directory or fallback to /app PROJECT_ROOT = Path("/projects/bloggingplatformapi-lncxqv") if PROJECT_ROOT.exists(): DB_DIR = PROJECT_ROOT / "storage" / "db" else: DB_DIR = Path("/app/storage/db") # Create the directory for the database if it doesn't exist 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)