]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Add support for kw to DROP INDEX, test postgresql_concurrently
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 Aug 2017 19:31:17 +0000 (15:31 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Aug 2017 14:45:44 +0000 (10:45 -0400)
Change-Id: I89c98401d3e1f1252041b622e045c6dc85fa59a1
Fixes: #424
alembic/operations/ops.py
docs/build/unreleased/424.rst [new file with mode: 0644]
tests/test_postgresql.py

index 101ec46f08be434c90b593a156c56daf45fac102..64a508e3b9b97c4e46d13886bfe5246e5d7b5614 100644 (file)
@@ -880,11 +880,13 @@ class DropIndexOp(MigrateOperation):
     """Represent a drop index operation."""
 
     def __init__(
-            self, index_name, table_name=None, schema=None, _orig_index=None):
+            self, index_name, table_name=None,
+            schema=None, _orig_index=None, **kw):
         self.index_name = index_name
         self.table_name = table_name
         self.schema = schema
         self._orig_index = _orig_index
+        self.kw = kw
 
     def to_diff_tuple(self):
         return ("remove_index", self.to_index())
@@ -902,7 +904,8 @@ class DropIndexOp(MigrateOperation):
             index.name,
             index.table.name,
             schema=index.table.schema,
-            _orig_index=index
+            _orig_index=index,
+            **index.kwargs
         )
 
     def to_index(self, migration_context=None):
@@ -914,14 +917,16 @@ class DropIndexOp(MigrateOperation):
         # need a dummy column name here since SQLAlchemy
         # 0.7.6 and further raises on Index with no columns
         return schema_obj.index(
-            self.index_name, self.table_name, ['x'], schema=self.schema)
+            self.index_name, self.table_name, ['x'],
+            schema=self.schema, **self.kw)
 
     @classmethod
     @util._with_legacy_names([
         ('name', 'index_name'),
         ('tablename', 'table_name')
     ])
-    def drop_index(cls, operations, index_name, table_name=None, schema=None):
+    def drop_index(cls, operations, index_name,
+                   table_name=None, schema=None, **kw):
         """Issue a "drop index" instruction using the current
         migration context.
 
@@ -940,13 +945,22 @@ class DropIndexOp(MigrateOperation):
          .. versionadded:: 0.7.0 'schema' can now accept a
             :class:`~sqlalchemy.sql.elements.quoted_name` construct.
 
+        :param \**kw: Additional keyword arguments not mentioned above are
+            dialect specific, and passed in the form
+            ``<dialectname>_<argname>``.
+            See the documentation regarding an individual dialect at
+            :ref:`dialect_toplevel` for detail on documented arguments.
+
+            .. versionadded:: 0.9.5 Support for dialect-specific keyword
+               arguments for DROP INDEX
+
         .. versionchanged:: 0.8.0 The following positional argument names
            have been changed:
 
            * name -> index_name
 
         """
-        op = cls(index_name, table_name=table_name, schema=schema)
+        op = cls(index_name, table_name=table_name, schema=schema, **kw)
         return operations.invoke(op)
 
     @classmethod
@@ -968,7 +982,7 @@ class DropIndexOp(MigrateOperation):
 
         op = cls(
             index_name, table_name=operations.impl.table_name,
-            schema=operations.impl.schema
+            schema=operations.impl.schema, **kw
         )
         return operations.invoke(op)
 
diff --git a/docs/build/unreleased/424.rst b/docs/build/unreleased/424.rst
new file mode 100644 (file)
index 0000000..4d07f58
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, postgresql
+    :tickets: 424
+
+    Added support for the dialect-specific keyword arguments
+    to :meth:`.Operations.drop_index`.   This includes support for
+    ``postgresql_concurrently`` and others.
index f02deeb9a7a4bf813f360fbc67bb6dfb81c3795a..afa9e7c26a36706a5faf1ab2a4a068a4d2c6c7a2 100644 (file)
@@ -69,6 +69,27 @@ class PostgresqlOpTest(TestBase):
             "CREATE INDEX geocoded ON locations (coordinates) "
             "WHERE locations.coordinates != Null")
 
+    @config.requirements.fail_before_sqla_099
+    def test_create_index_postgresql_concurrently(self):
+        context = op_fixture("postgresql")
+        op.create_index(
+            'geocoded',
+            'locations',
+            ['coordinates'],
+            postgresql_concurrently=True)
+        context.assert_(
+            "CREATE INDEX CONCURRENTLY geocoded ON locations (coordinates)")
+
+    @config.requirements.fail_before_sqla_110
+    def test_drop_index_postgresql_concurrently(self):
+        context = op_fixture("postgresql")
+        op.drop_index(
+            'geocoded',
+            'locations',
+            postgresql_concurrently=True)
+        context.assert_(
+            "DROP INDEX CONCURRENTLY geocoded")
+
     def test_alter_column_type_using(self):
         context = op_fixture('postgresql')
         op.alter_column("t", "c", type_=Integer, postgresql_using='c::integer')