Skip to content

Commit

Permalink
Remove postgres-specific parameteres to create_engine.
Browse files Browse the repository at this point in the history
The optimization for "executemany" that was needed in older SQLAlchemy
is no longer needed in 2.0 and default options should work now.
  • Loading branch information
andy-slac committed Dec 5, 2023
1 parent 6999ca1 commit 557e4ee
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions migrations/_alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from alembic import context
from sqlalchemy import engine, engine_from_config, pool
from sqlalchemy import engine_from_config, pool

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down Expand Up @@ -50,22 +50,9 @@ def run_migrations_online() -> None:
and associate a connection with the context.
"""
# executemany_* arguments are postgres-specific, need to check dialect
url_str = config.get_main_option("sqlalchemy.url")
assert url_str is not None, "Expect URL connection defined."
url = engine.url.make_url(url_str)
if url.get_dialect().name == "postgresql":
kwargs = dict(
executemany_mode="values",
executemany_values_page_size=10000,
executemany_batch_page_size=500,
)
else:
kwargs = {}

config_dict = config.get_section(config.config_ini_section)
assert config_dict is not None, "Expect non-empty configuration"
connectable = engine_from_config(config_dict, prefix="sqlalchemy.", poolclass=pool.NullPool, **kwargs)
connectable = engine_from_config(config_dict, prefix="sqlalchemy.", poolclass=pool.NullPool)

schema = config.get_section_option("daf_butler_migrate", "schema")
with connectable.connect() as connection:
Expand Down

0 comments on commit 557e4ee

Please sign in to comment.