def drop_index(self, idx):
self.batch.append(("drop_index", (idx,), {}))
+ def create_table_comment(self, table):
+ self.batch.append(("create_table_comment", (table,), {}))
+
+ def drop_table_comment(self, table):
+ self.batch.append(("drop_table_comment", (table,), {}))
+
def create_table(self, table):
raise NotImplementedError("Can't create table in batch mode")
"""
+ def create_table_comment(self, table):
+ """the batch table creation function will issue create_table_comment
+ on the real "impl" as part of the create table process.
+
+ """
+
+ def drop_table_comment(self, table):
+ """the batch table creation function will issue drop_table_comment
+ on the real "impl" as part of the create table process.
+
+ """
+
def add_constraint(self, const):
if not const.name:
raise ValueError("Constraint must have a name")
@Operations.register_operation("create_table_comment")
+@BatchOperations.register_operation(
+ "create_table_comment", "batch_create_table_comment"
+)
class CreateTableCommentOp(AlterTableOp):
"""Represent a COMMENT ON `table` operation."""
)
return operations.invoke(op)
+ @classmethod
+ def batch_create_table_comment(
+ cls,
+ operations,
+ comment,
+ existing_comment=None,
+ ):
+ """Emit a COMMENT ON operation to set the comment for a table
+ using the current batch migration context.
+
+ .. versionadded:: 1.6.0
+
+ :param comment: string value of the comment being registered against
+ the specified table.
+ :param existing_comment: String value of a comment
+ already registered on the specified table, used within autogenerate
+ so that the operation is reversible, but not required for direct
+ use.
+
+ """
+
+ op = cls(
+ operations.impl.table_name,
+ comment,
+ existing_comment=existing_comment,
+ schema=operations.impl.schema,
+ )
+ return operations.invoke(op)
+
def reverse(self):
"""Reverses the COMMENT ON operation against a table."""
if self.existing_comment is None:
@Operations.register_operation("drop_table_comment")
+@BatchOperations.register_operation(
+ "drop_table_comment", "batch_drop_table_comment"
+)
class DropTableCommentOp(AlterTableOp):
"""Represent an operation to remove the comment from a table."""
op = cls(table_name, existing_comment=existing_comment, schema=schema)
return operations.invoke(op)
+ @classmethod
+ def batch_drop_table_comment(cls, operations, existing_comment=None):
+ """Issue a "drop table comment" operation to
+ remove an existing comment set on a table using the current
+ batch operations context.
+
+ .. versionadded:: 1.6.0
+
+ :param existing_comment: An optional string value of a comment already
+ registered on the specified table.
+
+ """
+
+ op = cls(
+ operations.impl.table_name,
+ existing_comment=existing_comment,
+ schema=operations.impl.schema,
+ )
+ return operations.invoke(op)
+
def reverse(self):
"""Reverses the COMMENT ON operation against a table."""
return CreateTableCommentOp(
--- /dev/null
+.. change::
+ :tags: bug, batch
+ :tickets: 799
+
+ Added missing ``batch_op.create_table_comment()``,
+ ``batch_op.drop_table_comment()`` directives to batch ops.
\ No newline at end of file
]
)
+ def _assert_table_comment(self, tname, comment):
+ insp = inspect(config.db)
+
+ tcomment = insp.get_table_comment(tname)
+ eq_(tcomment, {"text": comment})
+
+ @config.requirements.comments
+ def test_add_table_comment(self):
+ with self.op.batch_alter_table("foo") as batch_op:
+ batch_op.create_table_comment("some comment")
+
+ self._assert_table_comment("foo", "some comment")
+
+ with self.op.batch_alter_table("foo") as batch_op:
+ batch_op.create_table_comment(
+ "some new comment", existing_comment="some comment"
+ )
+
+ self._assert_table_comment("foo", "some new comment")
+
+ @config.requirements.comments
+ def test_drop_table_comment(self):
+ with self.op.batch_alter_table("foo") as batch_op:
+ batch_op.create_table_comment("some comment")
+
+ with self.op.batch_alter_table("foo") as batch_op:
+ batch_op.drop_table_comment(existing_comment="some comment")
+
+ self._assert_table_comment("foo", None)
+
def _assert_column_comment(self, tname, cname, comment):
insp = inspect(config.db)