Opened 3 weeks ago
Last modified 3 weeks ago
#37151 assigned New feature
Add support for squashing across AddIndex, AddConstraint, and AlterConstraint
| Reported by: | Markus Holtermann | Owned by: | Markus Holtermann |
|---|---|---|---|
| Component: | Migrations | Version: | 6.0 |
| Severity: | Normal | Keywords: | migrations |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
The AddIndex, AddConstraint, and AlterConstraint migration operations straight out reject squashing across them.
Let's take the following set of operations:
[
migrations.CreateModel("A", fields=[("id", models.BigAutoField())]),
migrations.AddIndex("b", models.Index(fields=["id"], name="b_idx")),
migrations.AddField("a", "name", models.IntegerField()),
]
I would expect to get the following 2 operations:
[
migrations.AddIndex("b", models.Index(fields=["id"], name="b_idx")),
migrations.CreateModel("A", fields=[("id", models.BigAutoField()), ("name", models.IntegerField())]),
]
Instead, I end up with the same set of operations.
Change History (4)
comment:1 by , 3 weeks ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:2 by , 3 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 3 weeks ago
| Has patch: | set |
|---|
comment:4 by , 3 weeks ago
| Patch needs improvement: | set |
|---|
Left some comments on the MR.
We either need to drop the references_field optimization or implement it in a way that caters for all potential field references. The proposed changes disable the optimization in the presence of .expressions but it needs to do so when .include and .condition are present (or check them as well) and consider that .fields can contain descending order specifiers (e.g. Index(fields=['-pub_date'])).
I'm surprised to see that when we added
IndexOperationand friends we didn't realize thatAlterTogetherOptionOperationand friends were subclassingModelOptionOperationfor its.reduceoperation (which make us ofreferences_modelto implement what you're after here).This ticket seems to be about implementing model reference awareness but we could also implement field reference awareness (
references_field) not that we have the machinery to extra field references from expressions (seeIndex.checkfor example).