mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #18468 -- Added support for comments on columns and tables.
Thanks Jared Chung, Tom Carrick, David Smith, Nick Pope, and Mariusz Felisiak for reviews. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com> Co-authored-by: Nick Pope <nick@nickpope.me.uk>
This commit is contained in:
parent
68ef274bc5
commit
78f163a4fb
35 changed files with 846 additions and 37 deletions
|
@ -1922,6 +1922,37 @@ class OperationTests(OperationTestBase):
|
|||
operation.database_forwards(app_label, editor, new_state, project_state)
|
||||
self.assertColumnExists(rider_table, "pony_id")
|
||||
|
||||
@skipUnlessDBFeature("supports_comments")
|
||||
def test_alter_model_table_comment(self):
|
||||
app_label = "test_almotaco"
|
||||
project_state = self.set_up_test_model(app_label)
|
||||
pony_table = f"{app_label}_pony"
|
||||
# Add table comment.
|
||||
operation = migrations.AlterModelTableComment("Pony", "Custom pony comment")
|
||||
self.assertEqual(operation.describe(), "Alter Pony table comment")
|
||||
self.assertEqual(operation.migration_name_fragment, "alter_pony_table_comment")
|
||||
new_state = project_state.clone()
|
||||
operation.state_forwards(app_label, new_state)
|
||||
self.assertEqual(
|
||||
new_state.models[app_label, "pony"].options["db_table_comment"],
|
||||
"Custom pony comment",
|
||||
)
|
||||
self.assertTableCommentNotExists(pony_table)
|
||||
with connection.schema_editor() as editor:
|
||||
operation.database_forwards(app_label, editor, project_state, new_state)
|
||||
self.assertTableComment(pony_table, "Custom pony comment")
|
||||
# Reversal.
|
||||
with connection.schema_editor() as editor:
|
||||
operation.database_backwards(app_label, editor, new_state, project_state)
|
||||
self.assertTableCommentNotExists(pony_table)
|
||||
# Deconstruction.
|
||||
definition = operation.deconstruct()
|
||||
self.assertEqual(definition[0], "AlterModelTableComment")
|
||||
self.assertEqual(definition[1], [])
|
||||
self.assertEqual(
|
||||
definition[2], {"name": "Pony", "table_comment": "Custom pony comment"}
|
||||
)
|
||||
|
||||
def test_alter_field_pk(self):
|
||||
"""
|
||||
The AlterField operation on primary keys (things like PostgreSQL's
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue