#24535: Make "manage.py migrate" atomic, i.e. rolling back any migrations on
failure
-------------------------------+--------------------------------------
Reporter: Daniel Hahler | Owner: nobody
Type: New feature | Status: closed
Component: Migrations | Version: 1.7
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by Simon Charette):
Even if this limitation is now lifted it would still be impossible in the
case of non-atomic migrations/operations
[https://docs.djangoproject.com/en/3.0/howto/writing-migrations/#non-
atomic-migrations either explicit] or implicit because the database
backend doesn't support transactional DDL. The framework also defers quite
of bit of operations (search for usage of `deferred_sql` in the code base)
and some are
[https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/operations
/#index-concurrent-operations simply unsupported in a transaction].
If you really want to give this a go you can easily override the `migrate`
command by wrapping it's `handle` in an `atomic` block for the specified
`--database` but you have to keep in mind that'll likely break under
certain circumstances and it has the potential to take your side database
down if the transaction is held because of a long running operation.
If you really want to roll back on failure you can easily emulate such
thing by keeping track of where you are before performing migrating and
migrating to the previous state if any exception is raised. This is
something you can easily achieve with the commands the migration framework
currently exposes.
--
Ticket URL: <https://code.djangoproject.com/ticket/24535#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.1dbf0920fc85bbe7cbb3bfce69d5c784%40djangoproject.com.