mirror of
https://github.com/django/django.git
synced 2025-11-20 11:36:04 +00:00
Refs #35038 -- Reduced CreateModel/AlterConstraint operations when optimizing migrations.
This commit is contained in:
parent
bc1bfe12b6
commit
56f468681a
2 changed files with 63 additions and 0 deletions
|
|
@ -1434,6 +1434,54 @@ class OptimizerTests(OptimizerTestBase):
|
|||
],
|
||||
)
|
||||
|
||||
def test_create_model_alter_constraint(self):
|
||||
original_constraint = models.CheckConstraint(
|
||||
condition=models.Q(weight__gt=0), name="pony_weight_gt_0"
|
||||
)
|
||||
altered_constraint = models.CheckConstraint(
|
||||
condition=models.Q(weight__gt=0),
|
||||
name="pony_weight_gt_0",
|
||||
violation_error_message="incorrect weight",
|
||||
)
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
migrations.CreateModel(
|
||||
name="Pony",
|
||||
fields=[
|
||||
("weight", models.IntegerField()),
|
||||
],
|
||||
options={
|
||||
"constraints": [
|
||||
original_constraint,
|
||||
models.UniqueConstraint(
|
||||
"weight", name="pony_weight_unique"
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
migrations.AlterConstraint(
|
||||
"Pony", "pony_weight_gt_0", altered_constraint
|
||||
),
|
||||
],
|
||||
[
|
||||
migrations.CreateModel(
|
||||
name="Pony",
|
||||
fields=[
|
||||
("weight", models.IntegerField()),
|
||||
],
|
||||
options={
|
||||
"constraints": [
|
||||
models.UniqueConstraint(
|
||||
"weight",
|
||||
name="pony_weight_unique",
|
||||
),
|
||||
altered_constraint,
|
||||
]
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_create_model_remove_constraint(self):
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue