]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
restore drop_index.table_name, drop_constraint.type_ as positional
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 16 May 2023 12:55:51 +0000 (08:55 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 16 May 2023 17:50:09 +0000 (13:50 -0400)
These two API changes were identified as having legacy
use patterns and should be revisited using a deprecation warning
for removal in either 1.12 or 1.13.

Add documentation re: Alembic not using semver, fix
incorrect calling signature example in batch documentation.

Change-Id: I33dc5a8d058bcce77591bb037ae964e626a3387f
Fixes: #1243
Fixes: #1245
alembic/op.pyi
alembic/operations/base.py
alembic/operations/ops.py
docs/build/batch.rst
docs/build/front.rst
docs/build/unreleased/1243.rst [new file with mode: 0644]
tests/test_batch.py
tests/test_mssql.py
tests/test_mysql.py
tests/test_op.py

index 10e6f5914afbb149fe1cb0b81127180f8fd069d7..931f1bb2197d598d11aee595d80a79c1b9f4052f 100644 (file)
@@ -933,8 +933,8 @@ def drop_column(
 def drop_constraint(
     constraint_name: str,
     table_name: str,
-    *,
     type_: Optional[str] = None,
+    *,
     schema: Optional[str] = None,
 ) -> None:
     r"""Drop a constraint of the given name, typically via DROP CONSTRAINT.
@@ -952,8 +952,8 @@ def drop_constraint(
 
 def drop_index(
     index_name: str,
-    *,
     table_name: Optional[str] = None,
+    *,
     schema: Optional[str] = None,
     **kw: Any,
 ) -> None:
index 4e59e5ba56a3ce8f18438a0a9ec2ca4fd3a5d7fa..853e795ea980d32555766468dac1d3543597ed60 100644 (file)
@@ -1335,8 +1335,8 @@ class Operations(AbstractOperations):
             self,
             constraint_name: str,
             table_name: str,
-            *,
             type_: Optional[str] = None,
+            *,
             schema: Optional[str] = None,
         ) -> None:
             r"""Drop a constraint of the given name, typically via DROP CONSTRAINT.
@@ -1356,8 +1356,8 @@ class Operations(AbstractOperations):
         def drop_index(
             self,
             index_name: str,
-            *,
             table_name: Optional[str] = None,
+            *,
             schema: Optional[str] = None,
             **kw: Any,
         ) -> None:
@@ -1787,7 +1787,7 @@ class BatchOperations(AbstractOperations):
             ...
 
         def drop_constraint(
-            self, constraint_name: str, *, type_: Optional[str] = None
+            self, constraint_name: str, type_: Optional[str] = None
         ) -> None:
             """Issue a "drop constraint" instruction using the
             current batch migration context.
index 5334a01e0774511c3db93e126bb14f2f25b2466b..3c37fee5c96983131e0ae61a149ce48ec469e954 100644 (file)
@@ -132,8 +132,8 @@ class DropConstraintOp(MigrateOperation):
         self,
         constraint_name: Optional[sqla_compat._ConstraintNameDefined],
         table_name: str,
-        *,
         type_: Optional[str] = None,
+        *,
         schema: Optional[str] = None,
         _reverse: Optional[AddConstraintOp] = None,
     ) -> None:
@@ -196,8 +196,8 @@ class DropConstraintOp(MigrateOperation):
         operations: Operations,
         constraint_name: str,
         table_name: str,
-        *,
         type_: Optional[str] = None,
+        *,
         schema: Optional[str] = None,
     ) -> None:
         r"""Drop a constraint of the given name, typically via DROP CONSTRAINT.
@@ -221,7 +221,6 @@ class DropConstraintOp(MigrateOperation):
         cls,
         operations: BatchOperations,
         constraint_name: str,
-        *,
         type_: Optional[str] = None,
     ) -> None:
         """Issue a "drop constraint" instruction using the
@@ -1016,8 +1015,8 @@ class DropIndexOp(MigrateOperation):
     def __init__(
         self,
         index_name: Union[quoted_name, str, conv],
-        *,
         table_name: Optional[str] = None,
+        *,
         schema: Optional[str] = None,
         _reverse: Optional[CreateIndexOp] = None,
         **kw: Any,
@@ -1065,8 +1064,8 @@ class DropIndexOp(MigrateOperation):
         cls,
         operations: Operations,
         index_name: str,
-        *,
         table_name: Optional[str] = None,
+        *,
         schema: Optional[str] = None,
         **kw: Any,
     ) -> None:
index 6c2e9d42a67d2186bc21c09f0f04f52c0ef50232..b1a1022e09430e7c9809d3247f5b01f348440b91 100644 (file)
@@ -230,7 +230,7 @@ constraint named ``ck1``.  In order to drop this column, we have to drop
 the check constraint also::
 
     with self.op.batch_alter_table("some_table") as batch_op:
-        batch_op.drop_constraint("ck1", "check")
+        batch_op.drop_constraint("ck1", type_="check")
         batch_op.drop_column('q')
 
 .. versionchanged:: 1.7  Named CHECK constraints participate in batch mode
index f4eb660ba2a10b0738ebc816d9c66cb91ba503cd..5ca73e5fbe0cd914ea40e2e5b9fb4059b8991c48 100644 (file)
@@ -89,6 +89,34 @@ Alembic supports Python versions **3.7 and above**
 .. versionchanged::  1.7  Alembic now supports Python 3.6 and newer; support
    for Python 2.7 has been dropped.
 
+.. _versioning_scheme:
+
+Versioning Scheme
+-----------------
+
+Alembic's versioning scheme is based on that of
+`SQLAlchemy's versioning scheme <https://www.sqlalchemy.org/download.html#versions>`_.
+In particular, it should be noted that while Alembic uses a three-number
+versioning scheme, it **does not use SemVer**. In SQLAlchemy and Alembic's
+scheme, **the middle digit is considered to be a "Significant Minor Release",
+which may include removal of previously deprecated APIs with some risk of
+non-backwards compatibility in a very small number of cases**.
+
+This means that version "1.8.0", "1.9.0", "1.10.0", "1.11.0", etc. are
+**Significant Minor Releases**, which will include new API features and may
+remove or modify existing ones.
+
+Therefore, when `pinning <https://pip.pypa.io/en/stable/topics/repeatable-installs/>`_
+Alembic releases, pin to the "major" and "minor" digits to avoid API changes.
+
+A true "Major" release such as a change to "2.0" would include complete
+redesigns/re-architectures of foundational features; currently no such series
+of changes are planned, although changes such as replacing the entire
+"autogenerate" scheme with a new approach would qualify for that level of
+change.
+
+
+
 Community
 =========
 
diff --git a/docs/build/unreleased/1243.rst b/docs/build/unreleased/1243.rst
new file mode 100644 (file)
index 0000000..26c8e35
--- /dev/null
@@ -0,0 +1,21 @@
+.. change::
+    :tags: bug, autogenerate, regression
+    :tickets: 1243 1245
+
+    As Alembic 1.11.0 is considered a major release (Alembic does not use
+    semver, nor does its parent project SQLAlchemy; this has been
+    :ref:`clarified <versioning_scheme>` in the documentation), change
+    :ticket:`1130` modified calling signatures for most operations to consider
+    all optional keyword parameters to be keyword-only arguments, to match what
+    was always documented and generated by autogenerate. However, two of these
+    changes were identified as possibly problematic without a more formal
+    deprecation warning being emitted which were the ``table_name`` parameter
+    to :meth:`.Operations.drop_index`, which was generated positionally by
+    autogenerate prior to version 0.6.3 released in 2014, and ``type_`` in
+    :meth:`.Operations.drop_constraint` and
+    :meth:`.BatchOperations.drop_constraint`, which was documented positionally
+    in one example in the batch documentation. These two signatures have been
+    restored to allow those particular parameters to be passed positionally. A
+    future change will include formal deprecation paths (with warnings) for
+    these arguments where they will again become keyword-only in a future
+    "Significant Minor" release.
index 66d59fd441370e3555d6d90d118497d1e9b56137..5920cdf8fcb90b7e0f2195720d7ad30436e588d2 100644 (file)
@@ -1783,6 +1783,19 @@ class BatchRoundTripTest(TestBase):
         ck_consts = inspect(self.conn).get_check_constraints("ck_table")
         eq_(ck_consts, [])
 
+    @config.requirements.check_constraint_reflection
+    def test_drop_ck_constraint_legacy_type(self):
+        self._ck_constraint_fixture()
+
+        with self.op.batch_alter_table(
+            "ck_table", recreate="always"
+        ) as batch_op:
+            # matches the docs that were written for this originally
+            batch_op.drop_constraint("ck", "check")
+
+        ck_consts = inspect(self.conn).get_check_constraints("ck_table")
+        eq_(ck_consts, [])
+
     @config.requirements.unnamed_constraints
     def test_drop_foreign_key(self):
         bar = Table(
index b785e2f1c99b7fc036a29109be72b51de1b7bc64..693ab57dd1a84127063c70643f9e15baae6a9f4d 100644 (file)
@@ -161,6 +161,12 @@ class OpTest(TestBase):
         op.drop_index("my_idx", table_name="my_table")
         context.assert_contains("DROP INDEX my_idx ON my_table")
 
+    def test_drop_index_w_tablename_legacy(self):
+        """#1243"""
+        context = op_fixture("mssql")
+        op.drop_index("my_idx", "my_table")
+        context.assert_contains("DROP INDEX my_idx ON my_table")
+
     def test_drop_column_w_default(self):
         context = op_fixture("mssql")
         op.drop_column("t1", "c1", mssql_drop_default=True)
index fd3b18585a929de71702440714e35c1d4a7cfe75..c3ac9666111fca411f51848ef3590fe55bd2bab0 100644 (file)
@@ -399,6 +399,12 @@ class MySQLOpTest(TestBase):
         op.drop_constraint("f1", "t1", type_="foreignkey")
         context.assert_("ALTER TABLE t1 DROP FOREIGN KEY f1")
 
+    def test_drop_fk_legacy(self):
+        """#1245"""
+        context = op_fixture("mysql")
+        op.drop_constraint("f1", "t1", "foreignkey")
+        context.assert_("ALTER TABLE t1 DROP FOREIGN KEY f1")
+
     def test_drop_fk_quoted(self):
         context = op_fixture("mysql")
         op.drop_constraint("MyFk", "MyTable", type_="foreignkey")
index 35adeaf54f4ba7ff014ece72e597da7d750c08b4..6aca753d1ce4393f362396b634fd0c5bb2efc7da 100644 (file)
@@ -806,6 +806,17 @@ class OpTest(TestBase):
         op.drop_constraint("foo_bar_bat", "t1")
         context.assert_("ALTER TABLE t1 DROP CONSTRAINT foo_bar_bat")
 
+    def test_drop_constraint_type(self):
+        context = op_fixture()
+        op.drop_constraint("foo_bar_bat", "t1", type_="foreignkey")
+        context.assert_("ALTER TABLE t1 DROP CONSTRAINT foo_bar_bat")
+
+    def test_drop_constraint_legacy_type(self):
+        """#1245"""
+        context = op_fixture()
+        op.drop_constraint("foo_bar_bat", "t1", "foreignkey")
+        context.assert_("ALTER TABLE t1 DROP CONSTRAINT foo_bar_bat")
+
     def test_drop_constraint_schema(self):
         context = op_fixture()
         op.drop_constraint("foo_bar_bat", "t1", schema="foo")
@@ -856,6 +867,17 @@ class OpTest(TestBase):
         op.drop_index("ik_test")
         context.assert_("DROP INDEX ik_test")
 
+    def test_drop_index_w_tablename(self):
+        context = op_fixture()
+        op.drop_index("ik_test", table_name="the_table")
+        context.assert_("DROP INDEX ik_test")
+
+    def test_drop_index_w_tablename_legacy(self):
+        """#1243"""
+        context = op_fixture()
+        op.drop_index("ik_test", "the_table")
+        context.assert_("DROP INDEX ik_test")
+
     def test_drop_index_schema(self):
         context = op_fixture()
         op.drop_index("ik_test", schema="foo")