]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
repair sharing example
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Feb 2022 14:18:50 +0000 (09:18 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Feb 2022 14:18:50 +0000 (09:18 -0500)
the note re: "we dont have to guess" is wrong.
engine_from_config() returns an engine.   It seems
like this example was edited a few times and
was not completely checked (it was me, for sure).

for now just use two separate blocks to eliminate
any problems

Change-Id: Ib44671526d0f570ed88dd3b1c77d078c1afbf3eb

docs/build/cookbook.rst

index b5a4bb943c67fb4ea08045e19c0c9fe3385cbd24..06a807513e5a75ca773bc8d2b122979d33dd4f46 100644 (file)
@@ -233,21 +233,22 @@ Then in ``env.py``::
                 prefix='sqlalchemy.',
                 poolclass=pool.NullPool)
 
-        context.configure(
-            connection=connectable,
-            target_metadata=target_metadata
-        )
+            with connectable.connect() as connection:
+                context.configure(
+                    connection=connection, target_metadata=target_metadata
+                )
 
-        with context.begin_transaction():
-            context.run_migrations()
+                with context.begin_transaction():
+                    context.run_migrations()
+        else:
+            context.configure(
+                connection=connectable,
+                target_metadata=target_metadata
+            )
 
-.. versionchanged:: 1.4
+            with context.begin_transaction():
+                context.run_migrations()
 
-    Prior to this version, we used a "branched connection", by calling
-    :meth:`~sqlalchemy.engine.Connection.connect`.
-    This is now deprecated and unnecessary,
-    since we no longer have to guess if the given "connection"
-    is an ``Engine`` or ``Connection``, it is always a ``Connection``.
 
 .. _replaceable_objects: