Initial commit
This commit is contained in:
0
backend/app/db/__init__.py
Normal file
0
backend/app/db/__init__.py
Normal file
8
backend/app/db/base.py
Normal file
8
backend/app/db/base.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""Base model class for all database models."""
|
||||
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
# Base class for all SQLAlchemy models
|
||||
Base = declarative_base()
|
||||
|
||||
# Note: Model imports have been moved to alembic/env.py to avoid circular imports
|
||||
26
backend/app/db/session.py
Normal file
26
backend/app/db/session.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Database session management."""
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from app.config import settings
|
||||
|
||||
|
||||
# SQLite specific connection arguments
|
||||
connect_args = {}
|
||||
if settings.DATABASE_URL.startswith("sqlite"):
|
||||
connect_args = {"check_same_thread": False}
|
||||
|
||||
# Create database engine
|
||||
engine = create_engine(
|
||||
settings.DATABASE_URL,
|
||||
connect_args=connect_args,
|
||||
pool_pre_ping=True, # Verify connections before using
|
||||
echo=settings.DEBUG, # Log SQL queries in debug mode
|
||||
)
|
||||
|
||||
# Create session factory
|
||||
SessionLocal = sessionmaker(
|
||||
autocommit=False,
|
||||
autoflush=False,
|
||||
bind=engine
|
||||
)
|
||||
Reference in New Issue
Block a user