mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Refs #35038 -- Reduced CreateModel/AlterConstraint operations when optimizing migrations.
This commit is contained in:
@@ -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(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user