From: Martin Domke Date: Wed, 16 Mar 2016 16:35:28 +0000 (+0100) Subject: Allow server_default=None for batch operations. X-Git-Tag: rel_0_8_6~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8be52d559b940d0f23c11e09154d0a84013a80b;p=thirdparty%2Fsqlalchemy%2Falembic.git Allow server_default=None for batch operations. --- diff --git a/alembic/operations/batch.py b/alembic/operations/batch.py index d8bf0dff..2497e864 100644 --- a/alembic/operations/batch.py +++ b/alembic/operations/batch.py @@ -305,7 +305,10 @@ class ApplyBatchImpl(object): if nullable is not None: existing.nullable = nullable if server_default is not False: - sql_schema.DefaultClause(server_default)._set_parent(existing) + if server_default is None: + existing.server_default = None + else: + sql_schema.DefaultClause(server_default)._set_parent(existing) if autoincrement is not None: existing.autoincrement = bool(autoincrement) diff --git a/tests/test_batch.py b/tests/test_batch.py index 05bd3547..829dc1b1 100644 --- a/tests/test_batch.py +++ b/tests/test_batch.py @@ -161,6 +161,15 @@ class BatchApplyTest(TestBase): ) return ApplyBatchImpl(t, table_args, table_kwargs) + def _server_default_fixture(self, table_args=(), table_kwargs={}): + m = MetaData() + t = Table( + 'tname', m, + Column('id', Integer, primary_key=True), + Column('thing', String(), server_default='') + ) + return ApplyBatchImpl(t, table_args, table_kwargs) + def _assert_impl(self, impl, colnames=None, ddl_contains=None, ddl_not_contains=None, dialect='default', schema=None): @@ -360,6 +369,13 @@ class BatchApplyTest(TestBase): new_table.c.y.server_default.arg, "10" ) + def test_change_server_default(self): + impl = self._server_default_fixture() + impl.alter_column('tname', 'thing', server_default=None) + new_table = self._assert_impl( + impl, colnames=['id', 'thing'], ddl_not_contains="DEFAULT") + eq_(new_table.c.thing.server_default, None) + def test_rename_col_pk(self): impl = self._simple_fixture() impl.alter_column('tname', 'id', name='foobar')