def add_column(compiler, column, **kw):
- return "ADD COLUMN %s" % compiler.get_column_specification(column, **kw)
+ text = "ADD COLUMN %s" % compiler.get_column_specification(column, **kw)
+
+ const = " ".join(
+ compiler.process(constraint) for constraint in column.constraints
+ )
+ if const:
+ text += " " + const
+
+ return text
t = operations.schema_obj.table(table_name, column, schema=schema)
operations.impl.add_column(table_name, column, schema=schema, **kw)
+
for constraint in t.constraints:
if not isinstance(constraint, sa_schema.PrimaryKeyConstraint):
operations.impl.add_constraint(constraint)
--- /dev/null
+.. change::
+ :tags: bug, operations
+ :tickets: 655
+
+ Fixed long-standing bug where an inline column CHECK constraint would not
+ be rendered within an "ADD COLUMN" operation. The DDL compiler is now
+ consulted for inline constraints within the :meth:`.Operations.add_column`
+ method as is done for regular CREATE TABLE operations.
+
+
"""Test against the builders in the op.* module."""
from sqlalchemy import Boolean
+from sqlalchemy import CheckConstraint
from sqlalchemy import Column
from sqlalchemy import event
from sqlalchemy import exc
op.add_column("t1", Column("c1", Integer, nullable=False))
context.assert_("ALTER TABLE t1 ADD COLUMN c1 INTEGER NOT NULL")
+ def test_add_column_w_check(self):
+ context = op_fixture()
+ op.add_column(
+ "t1",
+ Column("c1", Integer, CheckConstraint("c1 > 5"), nullable=False),
+ )
+ context.assert_(
+ "ALTER TABLE t1 ADD COLUMN c1 INTEGER NOT NULL CHECK (c1 > 5)"
+ )
+
def test_add_column_schema(self):
context = op_fixture()
op.add_column(