Opened 9 years ago
Closed 4 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 )
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)
Change History (8)
by , 9 years ago
| Attachment: | optimizemigration.py added |
|---|
comment:1 by , 9 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 9 years ago
| Needs documentation: | set |
|---|---|
| Needs tests: | set |
| Summary: | Add a management command to run the optimizer on a single migration → Add a management command to optimize a migration |
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 4 years ago
| Cc: | added |
|---|---|
| Needs documentation: | unset |
| Needs tests: | unset |
| Owner: | changed from to |
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 , 4 years ago
| Needs documentation: | set |
|---|---|
| Needs tests: | set |
| Patch needs improvement: | set |
comment:5 by , 4 years ago
| Needs documentation: | unset |
|---|---|
| Needs tests: | unset |
| Patch needs improvement: | unset |
comment:6 by , 4 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
django-developers discussion from the reporter. Shai also proposed a similar thing.