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 Markus Holtermann, 3 weeks ago

Owner: set to Markus Holtermann
Status: newassigned

comment:2 by Simon Charette, 3 weeks ago

Triage Stage: UnreviewedAccepted

I'm surprised to see that when we added IndexOperation and friends we didn't realize that AlterTogetherOptionOperation and friends were subclassing ModelOptionOperation for its .reduce operation (which make us of references_model to 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 (see Index.check for example).

comment:3 by Markus Holtermann, 3 weeks ago

Has patch: set

comment:4 by Simon Charette, 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'])).

Note: See TracTickets for help on using tickets.
Back to Top