It's possible to manually remove such RunPython/RunSQL operations before
squashing, but it's a pain to review the whole history for such cases and
manually remove them.
I would find it useful to have an attribute like `elidable` or
`optimize_across` on migration operations (at least on `RunPython` and
`RunSQL`), settable via a kwarg to the constructor, which would default to
`False` (preserving the current behavior), but if set to `True` would mark
the migration as "safe to elide and optimize across". This would never be
set to `True` by the autodetector, it would only ever be set manually by
the user.
Thoughts?
--
Ticket URL: <https://code.djangoproject.com/ticket/24109>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by shaib):
While this appears to be a generally good idea, I think a better solution
for the use-case would be a specific data-move operation, if we can come
up with one that is general enough. Usually, the data-migration is needed
because old-field and new-field are not on the same model (incl. moving
from FK to M2M) -- or because some explicit transformation is required
(e.g. turning some field from string to number). These, I suspect, can be
collected into an operation that the optimizer and the executor can
understand, and perhaps could even be auto-detected in some way.
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:1>
Comment (by carljm):
That sounds very nice, though it's a much more complex proposal and I'm
not totally convinced about feasibility. If someone has a PR or POC
demonstrating how it would be done, I'm interested, but barring that I'd
still like to have at least the simpler manual version in place. (It seems
possible that your proposal could still build on top of the simpler API I
proposed, exposing both as options for when the higher-level approach
doesn't quite meet your case).
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:2>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:3>
Comment (by MarkusH):
The idea sounds good, Carl. I'm up for a review.
An automatic detection and output of alterations that includes migrating
data from A to B would be quite some feature, but I doubt that would work
reliable.
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:4>
Comment (by carljm):
#25413 was a duplicate that proposed an alternative solution: a flag you'd
pass to `squashmigrations` to automatically elide all `RunSQL` and
`RunPython` operations.
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:5>
* cc: mjtamlyn (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:6>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/5957 Tentative implementation]
given we want to/can move the operation reduction logic to their
respective class definition.
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:7>
* status: new => assigned
* owner: nobody => charettes
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:8>
* cc: ryan@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:9>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:10>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"729e0b086daac92bb9c6eb16f01cd2e13d258fdd" 729e0b08]:
{{{
#!CommitTicketReference repository=""
revision="729e0b086daac92bb9c6eb16f01cd2e13d258fdd"
Fixed #24109 -- Allowed RunSQL and RunPython operations to be elided.
Thanks to Markus Holtermann and Tim Graham for their review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:11>
Comment (by Tim Graham <timograham@…>):
In [changeset:"04446b60f29dcbadc1a73bd3a916dcf9a4b0f445" 04446b60]:
{{{
#!CommitTicketReference repository=""
revision="04446b60f29dcbadc1a73bd3a916dcf9a4b0f445"
[1.10.x] Refs #24109 -- Doc'd the elidable feature in squashing migrations
docs.
Backport of d1eda9b4ad47c7773e65d90fd882e9d07759fe41 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:12>
Comment (by Tim Graham <timograham@…>):
In [changeset:"d1eda9b4ad47c7773e65d90fd882e9d07759fe41" d1eda9b]:
{{{
#!CommitTicketReference repository=""
revision="d1eda9b4ad47c7773e65d90fd882e9d07759fe41"
Refs #24109 -- Doc'd the elidable feature in squashing migrations docs.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24109#comment:13>