
- Update OpenAI version to >=1.6.1 to resolve LangChain conflict
- Remove LangChain dependencies (not needed for this implementation)
- Fix OpenAI imports to use newer v1+ API format
- Make database and storage paths flexible for different environments
- Update Alembic configuration to use dynamic database paths
- Ensure compatibility across different deployment environments
🤖 Generated with BackendIM
Co-Authored-By: Claude <noreply@anthropic.com>
26 lines
648 B
Python
26 lines
648 B
Python
import os
|
|
from pathlib import Path
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
# Use current working directory if /app doesn't exist
|
|
base_path = Path("/app") if Path("/app").exists() else Path.cwd()
|
|
DB_DIR = base_path / "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() |