mirror of
https://github.com/django/django.git
synced 2024-11-24 20:07:01 +01:00
Fixed #35700 -- Added AlterModelTable and AlterModelTableComment reductions.
This commit is contained in:
parent
884ce37479
commit
20d44abb41
@ -184,6 +184,38 @@ class CreateModel(ModelOperation):
|
||||
managers=operation.managers,
|
||||
),
|
||||
]
|
||||
elif (
|
||||
isinstance(operation, AlterModelTable)
|
||||
and self.name_lower == operation.name_lower
|
||||
):
|
||||
return [
|
||||
CreateModel(
|
||||
self.name,
|
||||
fields=self.fields,
|
||||
options={
|
||||
**self.options,
|
||||
"db_table": operation.table,
|
||||
},
|
||||
bases=self.bases,
|
||||
managers=self.managers,
|
||||
),
|
||||
]
|
||||
elif (
|
||||
isinstance(operation, AlterModelTableComment)
|
||||
and self.name_lower == operation.name_lower
|
||||
):
|
||||
return [
|
||||
CreateModel(
|
||||
self.name,
|
||||
fields=self.fields,
|
||||
options={
|
||||
**self.options,
|
||||
"db_table_comment": operation.table_comment,
|
||||
},
|
||||
bases=self.bases,
|
||||
managers=self.managers,
|
||||
),
|
||||
]
|
||||
elif (
|
||||
isinstance(operation, AlterTogetherOptionOperation)
|
||||
and self.name_lower == operation.name_lower
|
||||
|
@ -154,6 +154,46 @@ class OptimizerTests(SimpleTestCase):
|
||||
],
|
||||
)
|
||||
|
||||
def test_create_alter_model_table(self):
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
migrations.CreateModel("Foo", fields=[]),
|
||||
migrations.AlterModelTable(
|
||||
name="foo",
|
||||
table="foo",
|
||||
),
|
||||
],
|
||||
[
|
||||
migrations.CreateModel(
|
||||
"Foo",
|
||||
fields=[],
|
||||
options={
|
||||
"db_table": "foo",
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_create_alter_model_table_comment(self):
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
migrations.CreateModel("Foo", fields=[]),
|
||||
migrations.AlterModelTableComment(
|
||||
name="foo",
|
||||
table_comment="A lovely table.",
|
||||
),
|
||||
],
|
||||
[
|
||||
migrations.CreateModel(
|
||||
"Foo",
|
||||
fields=[],
|
||||
options={
|
||||
"db_table_comment": "A lovely table.",
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_create_model_and_remove_model_options(self):
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
|
Loading…
Reference in New Issue
Block a user