From 07f04e35ec3c8de89d6ac2b09ef4179c46e42ed1 Mon Sep 17 00:00:00 2001 From: rkuo-danswer Date: Wed, 23 Apr 2025 12:21:34 -0700 Subject: [PATCH] Bugfix/alembic sqlengine (#4592) * need sqlengine to work * add comments --------- Co-authored-by: Richard Kuo (Onyx) --- backend/alembic/env.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/alembic/env.py b/backend/alembic/env.py index aa97f35241..e820fdf86c 100644 --- a/backend/alembic/env.py +++ b/backend/alembic/env.py @@ -24,6 +24,7 @@ from onyx.configs.constants import SSL_CERT_FILE from shared_configs.configs import MULTI_TENANT, POSTGRES_DEFAULT_SCHEMA from onyx.db.models import Base from celery.backends.database.session import ResultModelBase # type: ignore +from onyx.db.engine import SqlEngine # Make sure in alembic.ini [logger_root] level=INFO is set or most logging will be # hidden! (defaults to level=WARN) @@ -147,6 +148,9 @@ async def run_async_migrations() -> None: continue_on_error, ) = get_schema_options() + # without init_engine, subsequent engine calls fail hard intentionally + SqlEngine.init_engine(pool_size=20, max_overflow=5) + engine = create_async_engine( build_connection_string(), poolclass=pool.NullPool, @@ -202,10 +206,21 @@ async def run_async_migrations() -> None: def run_migrations_offline() -> None: - """This doesn't really get used when we migrate in the cloud.""" + """ + NOTE(rkuo): This generates a sql script that can be used to migrate the database ... + instead of migrating the db live via an open connection + + Not clear on when this would be used by us or if it even works. + + If it is offline, then why are there calls to the db engine? + + This doesn't really get used when we migrate in the cloud.""" logger.info("run_migrations_offline starting.") + # without init_engine, subsequent engine calls fail hard intentionally + SqlEngine.init_engine(pool_size=20, max_overflow=5) + schema_name, _, upgrade_all_tenants, continue_on_error = get_schema_options() url = build_connection_string()