A Django management commands to help on migrations deployment rollbacks
This is a fork of Jc2k's work, where I've made small fixes, build and distribuite as a pypi package
The idea here is that if you know which migrations were in version 2.0.3 of your project and which were in version 2.0.4 then setA - setB gives you the list of migrations you need to undo. See Design Implementation document.
pip install django-migrations-mgmt
settings.py
```python INSTALLED_APPS = [ … ‘migrations_mgmt_cmds', … ] … MIGRATIONS_RELEASES_STORAGE = ‘storages.backends.s3boto.S3BotoStorage'
key
of sorted
function.MIGRATIONS_RELEASES_SORTING = ‘migrations_mgmt_cmds.management.commands.release_management.default_sort_date' …
- Create a migration release
```sh
python manage.py migrations_release --release v0.1
ls
v0.1.json
python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sample_app, sessions
Running migrations:
Applying sample_app.0002_choice... OK
python manage.py migrations_rollback --release v0.1
Operations to perform:
Revert sample_app 0002_choice
Running migrations:
Rendering model states... DONE
Unapplying sample_app.0002_choice... OK
python manage.py showmigrations
The storage's backend to be used can be informed passing a class' path to the setting MIGRATIONS_RELEASES_STORAGE
, in case it isn't informed, the value set-up at Django's setting DEFAULT_FILE_STORAGE
will be used instead.
You should inform the path as python package, e.g. 'path.Classname'
release_management
This extension introduce a command to allow for displaying, disabling or deleting the release files available in the storage's backend:
# Display list of ordered release files with extension .json
python manage.py release_management --display-list
# Display last created file with extension .json
python manage.py release_management --display-last
# Delete a file informed by path from storage
python manage.py release_management --delete-release=<file's path in storage>
# Rename a release file informed by path from storage, appending `.disabled` to its filename.
python manage.py release_management --disable-release=<release file's path in storage>
It's quite common to change the database level constraints - for example to suddenly allow NULL data - which you'll almost certainly end up with data that doesn't satisfy this constraint, and consequenctly any attempt to revert will fail. Similar problems existing when changing the size of a field.
So relying on this as a strategy for backing our changes is risky! More testing should be added.
To avoid the rollback issues mentioned above please check the Django Migrations Good Practices documentation
Contributions, issues and feature requests are welcome!
Copyright © 2021 Italo Santos.
This project is GNU General Public License v2.0 licensed.
Give a ⭐️ if this project helped you!
👤 Italo Santos
This README was generated with by readme-md-generator