From: Mike Bayer Date: Wed, 30 Nov 2011 00:37:45 +0000 (-0500) Subject: dont need the const thing now that the batch separator is in use X-Git-Tag: rel_0_1_0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4dbb340fe9ff23da33506ff77d531a18a505f939;p=thirdparty%2Fsqlalchemy%2Falembic.git dont need the const thing now that the batch separator is in use --- diff --git a/alembic/ddl/mssql.py b/alembic/ddl/mssql.py index fc4c0f3f..8102e012 100644 --- a/alembic/ddl/mssql.py +++ b/alembic/ddl/mssql.py @@ -16,13 +16,6 @@ class MSSQLImpl(DefaultImpl): "mssql_batch_separator", self.batch_separator) - def start_migrations(self): - self.__dict__.pop('const_sym_counter', None) - - @util.memoized_property - def const_sym_counter(self): - return 1 - def _exec(self, construct, *args, **kw): super(MSSQLImpl, self)._exec(construct, *args, **kw) if self.as_sql and self.batch_separator: @@ -118,18 +111,14 @@ class MSSQLImpl(DefaultImpl): def _exec_drop_col_constraint(impl, tname, colname, type_): # from http://www.mssqltips.com/sqlservertip/1425/working-with-default-constraints-in-sql-server/ # TODO: needs table formatting, etc. - counter = impl.const_sym_counter - impl.const_sym_counter += 1 - - return """declare @const_name_%(sym)s varchar(256) -select @const_name_%(sym)s = [name] from %(type)s + return """declare @const_name varchar(256) +select @const_name = [name] from %(type)s where parent_object_id = object_id('%(tname)s') and col_name(parent_object_id, parent_column_id) = '%(colname)s' -exec('alter table %(tname)s drop constraint ' + @const_name_%(sym)s)""" % { +exec('alter table %(tname)s drop constraint ' + @const_name)""" % { 'type':type_, 'tname':tname, - 'colname':colname, - 'sym':counter + 'colname':colname } @compiles(AddColumn, 'mssql') diff --git a/tests/test_mssql.py b/tests/test_mssql.py index bdf8272d..dbdb0bac 100644 --- a/tests/test_mssql.py +++ b/tests/test_mssql.py @@ -62,24 +62,17 @@ class OpTest(TestCase): context = op_fixture('mssql') op.drop_column('t1', 'c1', mssql_drop_default=True) op.drop_column('t1', 'c2', mssql_drop_default=True) - context.assert_contains("exec('alter table t1 drop constraint ' + @const_name_1)") + context.assert_contains("exec('alter table t1 drop constraint ' + @const_name)") context.assert_contains("ALTER TABLE t1 DROP COLUMN c1") - # counter increments - context.assert_contains("exec('alter table t1 drop constraint ' + @const_name_2)") - context.assert_contains("ALTER TABLE t1 DROP COLUMN c2") def test_drop_column_w_check(self): context = op_fixture('mssql') op.drop_column('t1', 'c1', mssql_drop_check=True) op.drop_column('t1', 'c2', mssql_drop_check=True) - context.assert_contains("exec('alter table t1 drop constraint ' + @const_name_1)") + context.assert_contains("exec('alter table t1 drop constraint ' + @const_name)") context.assert_contains("ALTER TABLE t1 DROP COLUMN c1") - # counter increments - context.assert_contains("exec('alter table t1 drop constraint ' + @const_name_2)") - context.assert_contains("ALTER TABLE t1 DROP COLUMN c2") - def test_alter_column_nullable_w_existing_type(self): context = op_fixture('mssql') op.alter_column("t", "c", nullable=True, existing_type=Integer) @@ -128,7 +121,7 @@ class OpTest(TestCase): def test_alter_replace_server_default(self): context = op_fixture('mssql') op.alter_column("t", "c", server_default="5", existing_server_default="6") - context.assert_contains("exec('alter table t drop constraint ' + @const_name_1)") + context.assert_contains("exec('alter table t drop constraint ' + @const_name)") context.assert_contains( "ALTER TABLE t ADD DEFAULT '5' FOR c" ) @@ -136,7 +129,7 @@ class OpTest(TestCase): def test_alter_remove_server_default(self): context = op_fixture('mssql') op.alter_column("t", "c", server_default=None) - context.assert_contains("exec('alter table t drop constraint ' + @const_name_1)") + context.assert_contains("exec('alter table t drop constraint ' + @const_name)") def test_alter_do_everything(self): context = op_fixture('mssql')