Initial commit: Ballet Production Suite ERP/CRM foundation
This commit is contained in:
21
backend/database.py
Normal file
21
backend/database.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
from sqlmodel import create_engine, SQLModel, Session
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# Default to SQLite for easy development if not specified
|
||||
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./data/ballet_app.db")
|
||||
|
||||
# Use check_same_thread=False only for SQLite
|
||||
connect_args = {"check_same_thread": False} if DATABASE_URL.startswith("sqlite") else {}
|
||||
|
||||
engine = create_engine(DATABASE_URL, connect_args=connect_args, echo=True)
|
||||
|
||||
def create_db_and_tables():
|
||||
from . import models # Ensure models are registered
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
def get_session():
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
Reference in New Issue
Block a user