Opened 7 years ago

Closed 2 years ago

#27844 closed New feature (fixed)

Add a management command to optimize a migration

Reported by: Raphael Gaschignard Owned by: David Wobrock
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: David Wobrock Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Raphael Gaschignard)

Because the migration optimizer still has a bit of trouble with reducing operations, you often want to edit squashed migrations and re-run it through the optimizer.

The attached patch contains an implementation of a management command, optimizemigration, that will help speed up this process.

optimizemigration app_name migration_name reads a single migration, pass it through the optimizer, and then rewrite the result to disk. Unlike squashmigrations, this ignores things like the squashed-ness of the migration.

Attachments (1)

optimizemigration.py (3.1 KB ) - added by Raphael Gaschignard 7 years ago.

Download all attachments as: .zip

Change History (8)

by Raphael Gaschignard, 7 years ago

Attachment: optimizemigration.py added

comment:1 by Raphael Gaschignard, 7 years ago

Description: modified (diff)

comment:2 by Tim Graham, 7 years ago

Needs documentation: set
Needs tests: set
Summary: Add a management command to run the optimizer on a single migrationAdd a management command to optimize a migration
Triage Stage: UnreviewedAccepted

comment:3 by David Wobrock, 2 years ago

Cc: David Wobrock added
Needs documentation: unset
Needs tests: unset
Owner: changed from nobody to David Wobrock

Hi there,

Reviving this ticket, I think this command could be quite useful, especially when you upgrade Django on older projects, and new migration optimizations were added since.

I submitted a PR inspired by the attached patch.
PR

I made a quite specific choice for the logic of the command. By default, it overwrites the named migration. But if some manual porting is required, it will rather try to create a replacement migration. My thought was that, if functions need manual porting, we don't want to lose the code by overwriting the migration file.
Tell me what you think of this :)

comment:4 by Mariusz Felisiak, 2 years ago

Needs documentation: set
Needs tests: set
Patch needs improvement: set

comment:5 by David Wobrock, 2 years ago

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:6 by Mariusz Felisiak, 2 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 7c318a8b:

Fixed #27844 -- Added optimizemigration management command.

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