diff --git a/db_revisions/env.py b/db_revisions/env.py index 88d71fc..4a0c2d9 100644 --- a/db_revisions/env.py +++ b/db_revisions/env.py @@ -85,7 +85,27 @@ def run_migrations_online() -> None: and associate a connection with the context. """ - connectable = engine_from_config( + + connectable = context.config.attributes.get("connection", None) + + if connectable is None: + connectable = engine_from_config( + context.config.get_section(context.config.config_ini_section), + prefix="sqlalchemy.", + poolclass=pool.NullPool, + ) + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=target_metadata, + version_table_schema=target_metadata.schema, + include_object=include_object, + ) + + with context.begin_transaction(): + context.run_migrations() + """connectable = engine_from_config( config.get_section(config.config_ini_section, {}), prefix="sqlalchemy.", poolclass=pool.NullPool, @@ -100,7 +120,7 @@ def run_migrations_online() -> None: ) with context.begin_transaction(): - context.run_migrations() + context.run_migrations()""" if context.is_offline_mode(): diff --git a/tests/migrations/conftest.py b/tests/migrations/conftest.py index 78a5693..e965683 100644 --- a/tests/migrations/conftest.py +++ b/tests/migrations/conftest.py @@ -13,4 +13,4 @@ def alembic_config(): @pytest.fixture def alembic_engine(): """Override this fixture to provide pytest-alembic powered tests with a database handle.""" - return create_engine("sqlite:///") + return create_engine("sqlite+aiosqlite://")