File size: 667 Bytes
da8270e
437681a
 
 
 
da8270e
 
 
 
 
 
 
 
 
437681a
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# Ensure SQLite DB is created in a writable path for Hugging Face Spaces and local
DB_FILENAME = "app.db"
DB_PATH = os.path.join(os.getcwd(), DB_FILENAME)
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_PATH}"

# Create the database file if it doesn't exist (touch)
if not os.path.exists(DB_PATH):
    open(DB_PATH, "a").close()

engine = create_engine(
    SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()