From: Mike Bayer Date: Wed, 27 Nov 2013 00:14:27 +0000 (-0500) Subject: - Fixed bug where :func:`.op.alter_column` in the MySQL dialect X-Git-Tag: rel_0_6_1~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=085490b275cf24208376d48ce0b981d6c9adcbf3;p=thirdparty%2Fsqlalchemy%2Falembic.git - 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. #152 --- diff --git a/alembic/ddl/mysql.py b/alembic/ddl/mysql.py index ed48a59f..a505910d 100644 --- a/alembic/ddl/mysql.py +++ b/alembic/ddl/mysql.py @@ -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" ) diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index 7caf7112..4b921c7f 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -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 diff --git a/tests/test_mysql.py b/tests/test_mysql.py index 7f3a6313..58686901 100644 --- a/tests/test_mysql.py +++ b/tests/test_mysql.py @@ -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,