]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
clarify that only named check constraints are regenerated
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 1 Sep 2021 14:57:00 +0000 (10:57 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 1 Sep 2021 14:57:51 +0000 (10:57 -0400)
Change-Id: Ie0489137122d6ccedfa7c1af44dc8420a0842ee8
References: #400

docs/build/batch.rst

index 00ccc0f7b7d910a808f571ca0625844065a2761e..7b14a64ce06ca897304ca1c0ec0dd60b41802673 100644 (file)
@@ -243,11 +243,14 @@ the check constraint also::
    recreate operation.
 
 For **unnamed** CHECK constraints, these are still not automatically included
-as part of the batch process as they are often present due to the use of the
+as part of the batch process.  Note that this limitation **includes** the CHECK
+constraints generated by the
 :class:`~sqlalchemy.types.Boolean` or :class:`~sqlalchemy.types.Enum`
 datatypes, which up through SQLAlchemy 1.3 would generate CHECK constraints
-automatically and cannot be tracked to the reflected table. Therefore unnamed
-constraints can be stated explicitly if they are to be included in the
+automatically and cannot be tracked to the reflected table, assuming they are
+generated in an unnamed way.
+
+Unnamed constraints can be stated explicitly if they are to be included in the
 recreated table::
 
     with op.batch_alter_table("some_table", table_args=[
@@ -256,10 +259,16 @@ recreated table::
         batch_op.add_column(Column('foo', Integer))
         batch_op.drop_column('bar')
 
-Note this only includes CHECK constraints that are explicitly stated
-as part of the table definition, not the CHECK constraints that are generated
-by datatypes such as :class:`~sqlalchemy.types.Boolean` or
-:class:`~sqlalchemy.types.Enum`.
+The above step needs only be taken for CHECK constraints that are explicitly stated
+as part of the table definition.
+
+For CHECK constraints that are generated by datatypes such as
+:class:`~sqlalchemy.types.Boolean` or :class:`~sqlalchemy.types.Enum`, the type
+objects themselves **must be named** in order for their CHECK constraints to be
+included in the batch process.   Boolean and Enum datatypes that do not
+have the ``.name`` attribute set will **not** have CHECK constraints
+regenerated.  This name can be set by specifying the ``.name`` parameter
+or by using a named Python ``Enum`` object as the source of enumeration.
 
 Dealing with Referencing Foreign Keys
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^