File size: 715 Bytes
2d521fd
d761fc6
2d521fd
 
 
d761fc6
 
 
 
 
 
 
 
 
 
 
2d521fd
d761fc6
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from app.core.config import settings

# Use a default SQLite database if no URL is provided
if settings.database_url:
    DATABASE_URL = settings.database_url
else:
    # Fallback to a local SQLite file (writable in the container)
    DATABASE_URL = "sqlite:///./app.db"

# For SQLite, we need to disable the threading check
connect_args = {"check_same_thread": False} if DATABASE_URL.startswith("sqlite") else {}

engine = create_engine(DATABASE_URL, connect_args=connect_args)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()