[Django] #33402: Optimize multiple AlterFooTogether operations into one

12 views
Skip to first unread message

Django

unread,
Jan 1, 2022, 4:50:39 AM1/1/22
to django-...@googlegroups.com
#33402: Optimize multiple AlterFooTogether operations into one
-------------------------------------+-------------------------------------
Reporter: David | Owner: nobody
Wobrock |
Type: | Status: new
Cleanup/optimization |
Component: | Version: 4.0
Migrations | Keywords: alteruniquetogether
Severity: Normal | alterindextogether migration
Triage Stage: | optimizer
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hi,

In #31503 we split the `AlterFooTogether` (`AlterUniqueTogether` and
`AlterIndexTogether`) operations into two types of operations.
First, a migration will have operations to remove constraints, and then
other operations adds the new constraints. This allows field alterations
to work as expected during in between operations.

In some cases, this introduced two operations that can actually easily be
reduced to one.
See for instance the test case:
https://github.com/django/django/pull/14722/files#diff-
506caa00017053ff8278de6efc2e59cc0c5cea22da9461482bdf16a9fc50af9eR1573-R1592

Example:
{{{
operations = [
migrations.AlterUniqueTogether(
name='mymodel',
unique_together=set(),
),
migrations.AlterIndexTogether(
name='mymodel',
index_together=set(),
),
migrations.AlterUniqueTogether(
name='mymodel',
unique_together={("col",)},
),
migrations.AlterIndexTogether(
name='mymodel',
index_together={("col",)},
),
]
}}}
should be optimized to
{{{
operations = [
migrations.AlterUniqueTogether(
name='mymodel',
unique_together={("col",)},
),
migrations.AlterIndexTogether(
name='mymodel',
index_together={("col",)},
),
]
}}}

So that we don't do two operations on each constraint, but only one.

--
Ticket URL: <https://code.djangoproject.com/ticket/33402>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 1, 2022, 12:54:51 PM1/1/22
to django-...@googlegroups.com
#33402: Optimize multiple AlterFooTogether operations into one
-------------------------------------+-------------------------------------
Reporter: David Wobrock | Owner: David
Type: | Wobrock
Cleanup/optimization | Status: assigned
Component: Migrations | Version: 4.0
Severity: Normal | Resolution:
Keywords: alteruniquetogether | Triage Stage:
alterindextogether migration | Unreviewed
optimizer |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Wobrock):

* owner: nobody => David Wobrock
* status: new => assigned
* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/15268 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33402#comment:1>

Django

unread,
Jan 2, 2022, 7:57:29 AM1/2/22
to django-...@googlegroups.com
#33402: Optimize multiple AlterFooTogether operations into one
-------------------------------------+-------------------------------------
Reporter: David Wobrock | Owner: David
Type: | Wobrock
Cleanup/optimization | Status: assigned
Component: Migrations | Version: 4.0
Severity: Normal | Resolution:
Keywords: alteruniquetogether | Triage Stage: Accepted
alterindextogether migration |
optimizer |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/33402#comment:2>

Django

unread,
Jan 4, 2022, 12:13:38 AM1/4/22
to django-...@googlegroups.com
#33402: Optimize multiple AlterFooTogether operations into one
-------------------------------------+-------------------------------------
Reporter: David Wobrock | Owner: David
Type: | Wobrock
Cleanup/optimization | Status: assigned
Component: Migrations | Version: 4.0
Severity: Normal | Resolution:
Keywords: alteruniquetogether | Triage Stage: Ready for
alterindextogether migration | checkin
optimizer |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33402#comment:3>

Django

unread,
Jan 4, 2022, 12:24:14 AM1/4/22
to django-...@googlegroups.com
#33402: Optimize multiple AlterFooTogether operations into one
-------------------------------------+-------------------------------------
Reporter: David Wobrock | Owner: David
Type: | Wobrock
Cleanup/optimization | Status: closed
Component: Migrations | Version: 4.0
Severity: Normal | Resolution: fixed

Keywords: alteruniquetogether | Triage Stage: Ready for
alterindextogether migration | checkin
optimizer |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"482ee63b6f320cd4a834cb46fc651877bd2f2e28" 482ee63]:
{{{
#!CommitTicketReference repository=""
revision="482ee63b6f320cd4a834cb46fc651877bd2f2e28"
Fixed #33402 -- Optimized multiple AlterFooTogether operations.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33402#comment:4>

Reply all
Reply to author
Forward
0 new messages