]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- Fixed bug where :func:`.op.alter_column` in the MySQL dialect
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Nov 2013 00:14:27 +0000 (19:14 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Nov 2013 00:14:27 +0000 (19:14 -0500)
would fail to apply quotes to column names that had mixed casing
or spaces. #152

alembic/ddl/mysql.py
docs/build/changelog.rst
tests/test_mysql.py

index ed48a59f7adf0a459ee0819593088c1f5a3042e0..a505910d083cf12daf01f2f45bd45f45684f99c2 100644 (file)
@@ -6,7 +6,7 @@ from ..compat import string_types
 from .. import util
 from .impl import DefaultImpl
 from .base import ColumnNullable, ColumnName, ColumnDefault, \
-            ColumnType, AlterColumn
+            ColumnType, AlterColumn, format_column_name
 from .base import alter_table
 
 class MySQLImpl(DefaultImpl):
@@ -78,7 +78,7 @@ def _mysql_doesnt_support_individual(element, compiler, **kw):
 def _mysql_alter_column(element, compiler, **kw):
     return "%s CHANGE %s %s" % (
         alter_table(compiler, element.table_name, element.schema),
-        element.column_name,
+        format_column_name(compiler, element.column_name),
         _mysql_colspec(
             compiler,
             name=element.newname,
@@ -98,7 +98,7 @@ def _render_value(compiler, expr):
 def _mysql_colspec(compiler, name, nullable, server_default, type_,
                                         autoincrement):
     spec = "%s %s %s" % (
-        name,
+        format_column_name(compiler, name),
         compiler.dialect.type_compiler.process(type_),
         "NULL" if nullable else "NOT NULL"
     )
index 7caf711242aeaefe39adfec7ef0870d832b7808c..4b921c7f75ea19507fda1a5fea1d0468d7193cb2 100644 (file)
@@ -7,6 +7,14 @@ Changelog
     :version: 0.6.1
     :released: no release date
 
+    .. change::
+      :tags: bug, mysql
+      :tickets: 152
+
+      Fixed bug where :func:`.op.alter_column` in the MySQL dialect
+      would fail to apply quotes to column names that had mixed casing
+      or spaces.
+
     .. change::
       :tags: feature
       :pullreq: bitbucket:12
index 7f3a6313cbb9b979b87faba2f35d7ca66efc472a..58686901560d44e2741bd6c4c4dcb3d13a936e6d 100644 (file)
@@ -15,6 +15,22 @@ class MySQLOpTest(TestCase):
             'ALTER TABLE t1 CHANGE c1 c2 INTEGER NULL'
         )
 
+    def test_rename_column_quotes_needed_one(self):
+        context = op_fixture('mysql')
+        op.alter_column('MyTable', 'ColumnOne', new_column_name="ColumnTwo",
+                                existing_type=Integer)
+        context.assert_(
+            'ALTER TABLE `MyTable` CHANGE `ColumnOne` `ColumnTwo` INTEGER NULL'
+        )
+
+    def test_rename_column_quotes_needed_two(self):
+        context = op_fixture('mysql')
+        op.alter_column('my table', 'column one', new_column_name="column two",
+                                existing_type=Integer)
+        context.assert_(
+            'ALTER TABLE `my table` CHANGE `column one` `column two` INTEGER NULL'
+        )
+
     def test_rename_column_serv_default(self):
         context = op_fixture('mysql')
         op.alter_column('t1', 'c1', new_column_name="c2", existing_type=Integer,