]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Follow up Ia98c8f9a93953f049378f5029e355a3f249ed638
authorCaselIT <cfederico87@gmail.com>
Tue, 14 Feb 2023 20:52:33 +0000 (21:52 +0100)
committerCaselIT <cfederico87@gmail.com>
Tue, 14 Feb 2023 20:52:33 +0000 (21:52 +0100)
that was merged prematurely

Change-Id: I131dfb8dabf10457954f5216b1abadc976aebd38

alembic/templates/async/env.py
docs/build/cookbook.rst

index 847ac983cd2eb17c8b3632ebee6e8ed775d6d22d..9f2d51940080a1a7c954a8916dab86f00d5a4aa5 100644 (file)
@@ -59,13 +59,12 @@ def do_run_migrations(connection: Connection) -> None:
         context.run_migrations()
 
 
-async def run_migrations_online() -> None:
-    """Run migrations in 'online' mode.
-
-    In this scenario we need to create an Engine
+async def run_async_migrations() -> None:
+    """In this scenario we need to create an Engine
     and associate a connection with the context.
 
     """
+
     connectable = async_engine_from_config(
         config.get_section(config.config_ini_section, {}),
         prefix="sqlalchemy.",
@@ -78,7 +77,13 @@ async def run_migrations_online() -> None:
     await connectable.dispose()
 
 
+def run_migrations_online() -> None:
+    """Run migrations in 'online' mode."""
+
+    asyncio.run(run_async_migrations())
+
+
 if context.is_offline_mode():
     run_migrations_offline()
 else:
-    asyncio.run(run_migrations_online())
+    run_migrations_online()
index d50becc7dbde834444bba3b3058de5ad78228ffd..58a65ea5a8aae1c0472ec9becfd524f9226ccbc2 100644 (file)
@@ -1483,13 +1483,12 @@ file that's used by Alembic to start its operations. In particular only
             context.run_migrations()
 
 
-    async def run_migrations_online():
-        """Run migrations in 'online' mode.
-
-        In this scenario we need to create an Engine
+    async def run_async_migrations():
+        """In this scenario we need to create an Engine
         and associate a connection with the context.
 
         """
+
         connectable = async_engine_from_config(
             config.get_section(config.config_ini_section),
             prefix="sqlalchemy.",
@@ -1502,10 +1501,10 @@ file that's used by Alembic to start its operations. In particular only
         await connectable.dispose()
 
 
-    if context.is_offline_mode():
-        run_migrations_offline()
-    else:
-        asyncio.run(run_migrations_online())
+    def run_migrations_online():
+        """Run migrations in 'online' mode."""
+
+        asyncio.run(run_async_migrations())
 
 An async application can also interact with the Alembic api directly by using
 the SQLAlchemy ``run_sync`` method to adapt the non-async api of Alembic to
@@ -1518,30 +1517,7 @@ Programmatic API use (connection sharing) With Asyncio
 ------------------------------------------------------
 
 Combining the examples of :ref:`connection_sharing` with :ref:`asyncio_recipe`
-together, the ``env.py`` can be updated as follows works::
-
-    def do_run_migrations(connection):
-        context.configure(connection=connection, target_metadata=target_metadata)
-
-        with context.begin_transaction():
-            context.run_migrations()
-
-
-    async def run_async_migrations():
-        """In this scenario we need to create an Engine
-        and associate a connection with the context.
-        """
-
-        connectable = async_engine_from_config(
-            config.get_section(config.config_ini_section),
-            prefix="sqlalchemy.",
-            poolclass=pool.NullPool,
-        )
-
-        async with connectable.connect() as connection:
-            await connection.run_sync(do_run_migrations)
-
-        await connectable.dispose()
+together, the  ``env.py`` listed above can be updated as follows works::
 
 
     def run_migrations_online():
@@ -1556,12 +1532,6 @@ together, the ``env.py`` can be updated as follows works::
         else:
             do_run_migrations(connectable)
 
-
-    if context.is_offline_mode():
-        run_migrations_offline()
-    else:
-        run_migrations_online()
-
 Above, using an asyncio database URL in ``alembic.ini`` one can run
 commands such as ``alembic upgrade`` from the command line.  Programmatically,
 the same ``env.py`` file can be invoked using asyncio as::