mirror of
https://github.com/django/django.git
synced 2024-11-21 19:09:18 +01:00
Implemented reduce for optimizemigration.
This commit is contained in:
parent
93e88c1fc5
commit
b67602c74b
@ -1313,3 +1313,8 @@ class AlterConstraint(IndexOperation):
|
||||
@property
|
||||
def migration_name_fragment(self):
|
||||
return f"alter_{self.model_name_lower}_{self.constraint.name.lower()}"
|
||||
|
||||
def reduce(self, operation, app_label):
|
||||
if isinstance(operation, AlterConstraint):
|
||||
return [operation]
|
||||
return super().reduce(operation, app_label)
|
||||
|
@ -253,7 +253,7 @@ Management Commands
|
||||
Migrations
|
||||
~~~~~~~~~~
|
||||
|
||||
* The new operation `AlterConstraint` is a noop operation that alters
|
||||
* The new operation ``AlterConstraint`` is a no-op operation that alters
|
||||
constraints without dropping and recreating indexes in the database.
|
||||
|
||||
Models
|
||||
|
@ -1232,6 +1232,33 @@ class OptimizerTests(OptimizerTestBase):
|
||||
],
|
||||
)
|
||||
|
||||
def test_alter_constraint(self):
|
||||
gt_constraint = models.CheckConstraint(
|
||||
condition=models.Q(pink__gt=2), name="constraint_pony_pink_gt_2"
|
||||
)
|
||||
gt_constraint_violation_msg = models.CheckConstraint(
|
||||
condition=models.Q(pink__gt=2),
|
||||
name="constraint_pony_pink_gt_2",
|
||||
violation_error_message="error",
|
||||
)
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
migrations.AlterConstraint("Pony", gt_constraint.name, gt_constraint),
|
||||
migrations.AlterConstraint(
|
||||
"Pony",
|
||||
gt_constraint_violation_msg.name,
|
||||
gt_constraint_violation_msg,
|
||||
),
|
||||
],
|
||||
[
|
||||
migrations.AlterConstraint(
|
||||
"Pony",
|
||||
gt_constraint_violation_msg.name,
|
||||
gt_constraint_violation_msg,
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
def test_create_model_add_index(self):
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
|
Loading…
Reference in New Issue
Block a user