Skip to content

Commit

Permalink
- Fixed bug where :func:.op.alter_column in the MySQL dialect
Browse files Browse the repository at this point in the history
would fail to apply quotes to column names that had mixed casing
or spaces. #152
  • Loading branch information
zzzeek committed Nov 27, 2013
1 parent bc82988 commit 085490b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions alembic/ddl/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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):
Expand Down Expand Up @@ -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,
Expand All @@ -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"
)
Expand Down
8 changes: 8 additions & 0 deletions docs/build/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ def test_rename_column(self):
'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,
Expand Down

0 comments on commit 085490b

Please sign in to comment.