soem fixes
This commit is contained in:
@@ -86,19 +86,24 @@ async def init_db() -> None:
|
||||
db_url = _get_database_url()
|
||||
logger.info(f"Initializing database: {db_url}")
|
||||
|
||||
# Build engine kwargs based on database type
|
||||
is_sqlite = "sqlite" in db_url
|
||||
engine_kwargs = {
|
||||
"echo": settings.log_level == "DEBUG",
|
||||
"poolclass": pool.StaticPool if is_sqlite else pool.QueuePool,
|
||||
"pool_pre_ping": True,
|
||||
}
|
||||
|
||||
# Only add pool_size and max_overflow for non-SQLite databases
|
||||
if not is_sqlite:
|
||||
engine_kwargs["pool_size"] = 5
|
||||
engine_kwargs["max_overflow"] = 10
|
||||
|
||||
# Create async engine
|
||||
_engine = create_async_engine(
|
||||
db_url,
|
||||
echo=settings.log_level == "DEBUG",
|
||||
poolclass=pool.StaticPool if "sqlite" in db_url else pool.QueuePool,
|
||||
pool_size=5 if "sqlite" not in db_url else None,
|
||||
max_overflow=10 if "sqlite" not in db_url else None,
|
||||
pool_pre_ping=True,
|
||||
future=True,
|
||||
)
|
||||
_engine = create_async_engine(db_url, **engine_kwargs)
|
||||
|
||||
# Configure SQLite if needed
|
||||
if "sqlite" in db_url:
|
||||
if is_sqlite:
|
||||
_configure_sqlite_engine(_engine)
|
||||
|
||||
# Create async session factory
|
||||
@@ -112,12 +117,13 @@ async def init_db() -> None:
|
||||
|
||||
# Create sync engine for initial setup
|
||||
sync_url = settings.database_url
|
||||
_sync_engine = create_engine(
|
||||
sync_url,
|
||||
echo=settings.log_level == "DEBUG",
|
||||
poolclass=pool.StaticPool if "sqlite" in sync_url else pool.QueuePool,
|
||||
pool_pre_ping=True,
|
||||
)
|
||||
is_sqlite_sync = "sqlite" in sync_url
|
||||
sync_engine_kwargs = {
|
||||
"echo": settings.log_level == "DEBUG",
|
||||
"poolclass": pool.StaticPool if is_sqlite_sync else pool.QueuePool,
|
||||
"pool_pre_ping": True,
|
||||
}
|
||||
_sync_engine = create_engine(sync_url, **sync_engine_kwargs)
|
||||
|
||||
# Create sync session factory
|
||||
_sync_session_factory = sessionmaker(
|
||||
|
||||
Reference in New Issue
Block a user