diff options
-rw-r--r-- | alembic/operations/ops.py | 26 | ||||
-rw-r--r-- | docs/build/unreleased/424.rst | 7 | ||||
-rw-r--r-- | tests/test_postgresql.py | 21 |
3 files changed, 48 insertions, 6 deletions
diff --git a/alembic/operations/ops.py b/alembic/operations/ops.py index 101ec46..64a508e 100644 --- a/alembic/operations/ops.py +++ b/alembic/operations/ops.py @@ -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 index 0000000..4d07f58 --- /dev/null +++ b/docs/build/unreleased/424.rst @@ -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. diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index f02deeb..e52b555 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -69,6 +69,27 @@ class PostgresqlOpTest(TestBase): "CREATE INDEX geocoded ON locations (coordinates) " "WHERE locations.coordinates != Null") + @config.requirements.fail_before_sqla_110 + 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') |