]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
MS SQL is using sp_rename instead of Alter table to rename table
authorŁukasz Bołdys <mail@utek.pl>
Tue, 9 Sep 2014 08:12:12 +0000 (10:12 +0200)
committerŁukasz Bołdys <mail@utek.pl>
Tue, 9 Sep 2014 08:12:12 +0000 (10:12 +0200)
alembic/ddl/mssql.py
tests/test_mssql.py

index fece08bd0d4dabfdca206a9519aab965af550130..a3c67d6689efce1e7b6f5caffd230df95c4d321a 100644 (file)
@@ -2,7 +2,7 @@ from sqlalchemy.ext.compiler import compiles
 
 from .. import util
 from .impl import DefaultImpl
-from .base import alter_table, AddColumn, ColumnName, \
+from .base import alter_table, AddColumn, ColumnName, RenameTable,\
     format_table_name, format_column_name, ColumnNullable, alter_column,\
     format_server_default,ColumnDefault, format_type, ColumnType
 from sqlalchemy.sql.expression import ClauseElement, Executable
@@ -215,3 +215,9 @@ def visit_column_type(element, compiler, **kw):
         format_type(compiler, element.type_)
     )
 
+@compiles(RenameTable, 'mssql')
+def visit_rename_table(element, compiler, **kw):
+    return "EXEC sp_rename '%s', %s" % (
+        format_table_name(compiler, element.table_name, element.schema),
+        format_table_name(compiler, element.new_table_name, element.schema)
+    )
index 5fa6c4b2c15a1d1fa25051993d39c7abed91ecee..a18abfe2ab142b33132a11896cff2fe9960ae20c 100644 (file)
@@ -193,6 +193,11 @@ class OpTest(TestCase):
             "EXEC sp_rename 't.c', c2, 'COLUMN'"
         )
 
+    def test_rename_table(self):
+        context = op_fixture('mssql')
+        op.rename_table('t1', 't2')
+        context.assert_containt("EXEC sp_rename '[t1]', [t2]")
+
     # TODO: when we add schema support
     #def test_alter_column_rename_mssql_schema(self):
     #    context = op_fixture('mssql')