from sqlalchemy import sql
from .base import alter_table
+from .base import ColumnName
+from .base import format_column_name
from .base import format_table_name
from .base import RenameTable
from .impl import DefaultImpl
)
+@compiles(ColumnName, "sqlite")
+def visit_column_name(element: ColumnName, compiler: DDLCompiler, **kw) -> str:
+ return "%s RENAME COLUMN %s TO %s" % (
+ alter_table(compiler, element.table_name, element.schema),
+ format_column_name(compiler, element.column_name),
+ format_column_name(compiler, element.newname),
+ )
+
+
# @compiles(AddColumn, 'sqlite')
# def visit_add_column(element, compiler, **kw):
# return "%s %s" % (
--- /dev/null
+.. change::
+ :tags: usecase, sqlite
+ :tickets: 1576
+
+ Modified SQLite's dialect to render "ALTER TABLE <t> RENAME COLUMN" when
+ :meth:`.Operations.alter_column` is used with a straight rename, supporting
+ SQLite's recently added column rename feature.
op.add_column("t1", Column("c1", Integer))
context.assert_("ALTER TABLE t1 ADD COLUMN c1 INTEGER")
+ def test_rename_column(self):
+ context = op_fixture("sqlite")
+ op.alter_column("t1", column_name="old", new_column_name="new")
+ context.assert_("ALTER TABLE t1 RENAME COLUMN old TO new")
+
def test_add_column_implicit_constraint(self):
context = op_fixture("sqlite")
op.add_column("t1", Column("c1", Boolean))