diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-06-19 06:22:23 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-19 12:22:23 +0200 |
| commit | 56f468681aaedefcdada1b86c441c12ae96e7fea (patch) | |
| tree | 5203a04706794d2da757e835c926ce377a6882d1 /tests | |
| parent | bc1bfe12b613334bd625aeb36fd44af96d186c10 (diff) | |
Refs #35038 -- Reduced CreateModel/AlterConstraint operations when optimizing migrations.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_optimizer.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/migrations/test_optimizer.py b/tests/migrations/test_optimizer.py index a871e67a45..195a74072a 100644 --- a/tests/migrations/test_optimizer.py +++ b/tests/migrations/test_optimizer.py @@ -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( [ |
