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):
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,
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"
)
'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,