]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- [bug] Fixed alteration of column type on
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Jan 2012 20:25:30 +0000 (15:25 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Jan 2012 20:25:30 +0000 (15:25 -0500)
  MSSQL to not include the keyword "TYPE".

CHANGES
alembic/ddl/mssql.py
tests/test_mssql.py
tests/test_op.py

diff --git a/CHANGES b/CHANGES
index c34c8bc73cbcfce281dd404d5be74102a663600f..52f48444faf351d848ac14f25259d2088dca1da8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,9 @@
   "scripts/alembic" as setuptools creates this
   for us.  [#22]
 
+- [bug] Fixed alteration of column type on 
+  MSSQL to not include the keyword "TYPE".
+
 0.1.1
 =====
 - [bug] Clean up file write operations so that
index 8102e012ae6fdc8fdaf985fe7c04abe1662cb9a3..2f8c9ebc6cdb9e967ea47120456b1f167d325430 100644 (file)
@@ -1,7 +1,7 @@
 from alembic.ddl.impl import DefaultImpl
 from alembic.ddl.base import alter_table, AddColumn, ColumnName, \
     format_table_name, format_column_name, ColumnNullable, alter_column,\
-    format_server_default,ColumnDefault, format_type
+    format_server_default,ColumnDefault, format_type, ColumnType
 from alembic import util
 from sqlalchemy.ext.compiler import compiles
 
@@ -158,4 +158,11 @@ def visit_rename_column(element, compiler, **kw):
         format_column_name(compiler, element.newname)
     )
 
+@compiles(ColumnType, 'mssql')
+def visit_column_type(element, compiler, **kw):
+    return "%s %s %s" % (
+        alter_table(compiler, element.table_name, element.schema),
+        alter_column(compiler, element.column_name),
+        format_type(compiler, element.type_)
+    )
 
index 88ed9b52a218477c4b213c3d8307e22f8999937e..ed4751ee30e7906ac7ea4bea455240683381496d 100644 (file)
@@ -58,6 +58,13 @@ class OpTest(TestCase):
             "EXEC sp_rename 't.c', 'x', 'COLUMN'"
         )
 
+    def test_alter_column_new_type(self):
+        context = op_fixture('mssql')
+        op.alter_column("t", "c", type_=Integer)
+        context.assert_(
+            'ALTER TABLE t ALTER COLUMN c INTEGER'
+        )
+
     def test_drop_column_w_default(self):
         context = op_fixture('mssql')
         op.drop_column('t1', 'c1', mssql_drop_default=True)
index fe8bf29695c273348cca9fc971985630a2620c30..c85869a85f5884036f1e099159fb45a6528c3862 100644 (file)
@@ -124,7 +124,7 @@ def test_alter_column_schema_type_unnamed():
     context = op_fixture('mssql')
     op.alter_column("t", "c", type_=Boolean())
     context.assert_(
-        'ALTER TABLE t ALTER COLUMN c TYPE BIT',
+        'ALTER TABLE t ALTER COLUMN c BIT',
         'ALTER TABLE t ADD CHECK (c IN (0, 1))'
     )
 
@@ -132,7 +132,7 @@ def test_alter_column_schema_type_named():
     context = op_fixture('mssql')
     op.alter_column("t", "c", type_=Boolean(name="xyz"))
     context.assert_(
-        'ALTER TABLE t ALTER COLUMN c TYPE BIT',
+        'ALTER TABLE t ALTER COLUMN c BIT',
         'ALTER TABLE t ADD CONSTRAINT xyz CHECK (c IN (0, 1))'
     )
 
@@ -141,7 +141,7 @@ def test_alter_column_schema_type_existing_type():
     op.alter_column("t", "c", type_=String(10), existing_type=Boolean(name="xyz"))
     context.assert_(
         'ALTER TABLE t DROP CONSTRAINT xyz',
-        'ALTER TABLE t ALTER COLUMN c TYPE VARCHAR(10)'
+        'ALTER TABLE t ALTER COLUMN c VARCHAR(10)'
     )
 
 def test_add_foreign_key():