mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #34534 -- Reduced constraint operations with Meta.constraints when optimizing migrations.
This commit is contained in:
committed by
Mariusz Felisiak
parent
9c5e382b98
commit
8b7ddd1b62
@@ -1326,3 +1326,66 @@ class OptimizerTests(SimpleTestCase):
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_create_model_add_constraint(self):
|
||||
gt_constraint = models.CheckConstraint(
|
||||
check=models.Q(weight__gt=0), name="pony_weight_gt_0"
|
||||
)
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
migrations.CreateModel(
|
||||
name="Pony",
|
||||
fields=[
|
||||
("weight", models.IntegerField()),
|
||||
],
|
||||
),
|
||||
migrations.AddConstraint("Pony", gt_constraint),
|
||||
],
|
||||
[
|
||||
migrations.CreateModel(
|
||||
name="Pony",
|
||||
fields=[
|
||||
("weight", models.IntegerField()),
|
||||
],
|
||||
options={"constraints": [gt_constraint]},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_create_model_remove_constraint(self):
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
migrations.CreateModel(
|
||||
name="Pony",
|
||||
fields=[
|
||||
("weight", models.IntegerField()),
|
||||
],
|
||||
options={
|
||||
"constraints": [
|
||||
models.CheckConstraint(
|
||||
check=models.Q(weight__gt=0), name="pony_weight_gt_0"
|
||||
),
|
||||
models.UniqueConstraint(
|
||||
"weight", name="pony_weight_unique"
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
migrations.RemoveConstraint("Pony", "pony_weight_gt_0"),
|
||||
],
|
||||
[
|
||||
migrations.CreateModel(
|
||||
name="Pony",
|
||||
fields=[
|
||||
("weight", models.IntegerField()),
|
||||
],
|
||||
options={
|
||||
"constraints": [
|
||||
models.UniqueConstraint(
|
||||
"weight", name="pony_weight_unique"
|
||||
),
|
||||
]
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user