Automated Action 66f95ea88e Fix database path for standalone environment
- Modified database connection to use project-relative paths
- Updated Alembic configuration to dynamically use the SQLAlchemy URL
- Added a root endpoint for easy testing
- Fixed imports in migration environment
2025-05-18 19:15:35 +00:00

29 lines
771 B
Python

from pathlib import Path
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, Session
# Get the project root directory
PROJECT_ROOT = Path(__file__).parent.parent.parent.absolute()
DB_DIR = PROJECT_ROOT / "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()
metadata = MetaData()
# Dependency
def get_db() -> Session:
db = SessionLocal()
try:
yield db
finally:
db.close()