]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
dont need the const thing now that the batch separator is in use
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Nov 2011 00:37:45 +0000 (19:37 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Nov 2011 00:37:45 +0000 (19:37 -0500)
alembic/ddl/mssql.py
tests/test_mssql.py

index fc4c0f3f1afc5df5795484926504bd2f76e754e0..8102e012ae6fdc8fdaf985fe7c04abe1662cb9a3 100644 (file)
@@ -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')
index bdf8272d4917a1330150272bba409536b24bd782..dbdb0bac4985c3be857a3c3623f6b8b4385c3d7b 100644 (file)
@@ -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')