Automated Action fb53d13646 Fix database path to use local storage directory instead of /app
Fixed the database path in the application to use a local path relative to the project directory instead of /app/storage/db. This helps resolve permission issues and makes deployment more flexible.

generated with BackendIM... (backend.im)
2025-05-13 17:10:18 +00:00

33 lines
809 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
# Create database directory using a local path
BASE_DIR = Path(__file__).resolve().parent.parent
DB_DIR = BASE_DIR / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
# Database URL
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
# Create SQLAlchemy engine
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
# Create SessionLocal class
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Create Base class
Base = declarative_base()
# Dependency
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()