From fb81b7eba418cd624d431fbdceee6bcd07b9b0ff Mon Sep 17 00:00:00 2001 From: Michal Petrucha Date: Thu, 21 Jan 2016 11:13:56 +0100 Subject: [PATCH] Fixed mssql_* kwargs in batch_op.drop_column(). --- alembic/operations/ops.py | 4 ++-- tests/test_mssql.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/alembic/operations/ops.py b/alembic/operations/ops.py index 839c2da2..dbae84b4 100644 --- a/alembic/operations/ops.py +++ b/alembic/operations/ops.py @@ -1637,7 +1637,7 @@ class DropColumnOp(AlterTableOp): return operations.invoke(op) @classmethod - def batch_drop_column(cls, operations, column_name): + def batch_drop_column(cls, operations, column_name, **kw): """Issue a "drop column" instruction using the current batch migration context. @@ -1648,7 +1648,7 @@ class DropColumnOp(AlterTableOp): """ op = cls( operations.impl.table_name, column_name, - schema=operations.impl.schema) + schema=operations.impl.schema, **kw) return operations.invoke(op) diff --git a/tests/test_mssql.py b/tests/test_mssql.py index 0ec18e2b..ce91f999 100644 --- a/tests/test_mssql.py +++ b/tests/test_mssql.py @@ -109,6 +109,15 @@ class OpTest(TestBase): "exec('alter table t1 drop constraint ' + @const_name)") context.assert_contains("ALTER TABLE t1 DROP COLUMN c1") + def test_drop_column_w_default_in_batch(self): + context = op_fixture('mssql') + with op.batch_alter_table('t1', schema=None) as batch_op: + batch_op.drop_column('c1', mssql_drop_default=True) + batch_op.drop_column('c2', mssql_drop_default=True) + context.assert_contains( + "exec('alter table t1 drop constraint ' + @const_name)") + context.assert_contains("ALTER TABLE t1 DROP COLUMN c1") + def test_alter_column_drop_default(self): context = op_fixture('mssql') op.alter_column("t", "c", server_default=None) @@ -133,6 +142,15 @@ class OpTest(TestBase): "exec('alter table t1 drop constraint ' + @const_name)") context.assert_contains("ALTER TABLE t1 DROP COLUMN c1") + def test_drop_column_w_check_in_batch(self): + context = op_fixture('mssql') + with op.batch_alter_table('t1', schema=None) as batch_op: + batch_op.drop_column('c1', mssql_drop_check=True) + batch_op.drop_column('c2', mssql_drop_check=True) + context.assert_contains( + "exec('alter table t1 drop constraint ' + @const_name)") + context.assert_contains("ALTER TABLE t1 DROP COLUMN c1") + def test_drop_column_w_check_quoting(self): context = op_fixture('mssql') op.drop_column('table', 'column', mssql_drop_check=True) @@ -154,6 +172,14 @@ class OpTest(TestBase): "exec('alter table t1 drop constraint ' + @const_name)") context.assert_contains("ALTER TABLE t1 DROP COLUMN c1") + def test_drop_column_w_fk_in_batch(self): + context = op_fixture('mssql') + with op.batch_alter_table('t1', schema=None) as batch_op: + batch_op.drop_column('c1', mssql_drop_foreign_key=True) + context.assert_contains( + "exec('alter table t1 drop constraint ' + @const_name)") + context.assert_contains("ALTER TABLE t1 DROP COLUMN c1") + def test_alter_column_not_nullable_w_existing_type(self): context = op_fixture('mssql') op.alter_column("t", "c", nullable=False, existing_type=Integer) -- 2.47.2