type_ = op.modify_type
nullable = op.modify_nullable
comment = op.modify_comment
- newname = op.modify_name
autoincrement = op.kw.get("autoincrement", None)
existing_type = op.existing_type
existing_nullable = op.existing_nullable
rendered = _render_server_default(server_default, autogen_context)
text += ",\n%sserver_default=%s" % (indent, rendered)
- if newname is not None:
- text += ",\n%snew_column_name=%r" % (indent, newname)
if type_ is not None:
text += ",\n%stype_=%s" % (indent, _repr_type(type_, autogen_context))
if nullable is not None:
compiler: DDLCompiler,
default: Optional[_ServerDefault],
) -> str:
- # this can be updated to use compiler.render_default_string
- # for SQLAlchemy 2.0 and above; not in 1.4
- default_str = compiler.get_column_default_string(
+ return compiler.get_column_default_string(
Column("x", Integer, server_default=default)
)
- assert default_str is not None
- return default_str
def format_type(compiler: DDLCompiler, type_: TypeEngine) -> str:
from sqlalchemy.engine.reflection import Inspector
from sqlalchemy.sql import ClauseElement
from sqlalchemy.sql import Executable
+ from sqlalchemy.sql.elements import ColumnElement
from sqlalchemy.sql.elements import quoted_name
from sqlalchemy.sql.schema import Constraint
from sqlalchemy.sql.schema import ForeignKeyConstraint
def drop_table_comment(self, table: Table) -> None:
self._exec(schema.DropTableComment(table))
- def create_column_comment(self, column: Column[Any]) -> None:
+ def create_column_comment(self, column: ColumnElement[Any]) -> None:
self._exec(schema.SetColumnComment(column))
def drop_index(self, index: Index, **kw: Any) -> None:
{"from mypackage import MySpecialType"},
)
- def test_render_modify_name(self):
- op_obj = ops.AlterColumnOp(
- "sometable",
- "somecolumn",
- modify_name="newcolumnname",
- )
- eq_ignore_whitespace(
- autogenerate.render_op_text(self.autogen_context, op_obj),
- "op.alter_column('sometable', 'somecolumn', "
- "new_column_name='newcolumnname')",
- )
-
def test_render_modify_type(self):
op_obj = ops.AlterColumnOp(
"sometable",