django-migration-resolver-hook
Django Migration resolver ensures that migration files always stays ordered regardless of remote changes.
Problem:
With generated migration files using Django's manage.py makemigrations command you could run
into issues where the generated migration files would potentially be out of sync with
remote's default branch most CI servers are able to catch this error by running a test based on
your local branch merge back into the base branch there by spotting duplicate migration nodes.
Solution:
This package aims to solve this problem by using a Doubly Linked List while traversing the app's migration file(s) detecting duplicate node(s) and potential conflicts.
When duplicate nodes are detected stat.st_mtime is used to sort files based on the last modified time.
⚠️ This is not always accurate and might require a manual check to validate changes.
NOTE: This doesn't require Django's installed apps concept when using CLI commands since this is totally file based and should be executed within the root/app folders.
Table of Contents
Installation
$ pip install django-migration-resolver-hook
Poetry
poetry add -D django-migration-resolver-hook
Usage
Use Case
Remote
|--- migrations
|---- ...
|---- 0007_auto_20200112_2328.py # Shared between remote and local repo
|---- 0008_auto_20200113_4328.py # Only exists on remote
|---- 0009_auto_20200114_4532.py
|---- 0010_auto_20200115_1632.py
Local repo
|--- migrations
|---- ...
|---- 0007_auto_20200112_2328.py # Shared between remote and local repo
|---- 0008_auto_20200114_5438.py # Only exists locally which raises duplicate migration nodes errors.
Since this is now out of sync with the remote branch to sync changes:
⚠️ Unstable use Static migration resolver instead.
Using Auto migration resolver
CLI command: auto_migration_resolver
Auto detect and fix migration files by providing the following:
--app-name: The app_name of the Django application.--strategy: The strategy used to resolve migration errors (options: "reseed"/"inline"). (Defaults to: "reseed")--exclude: The list of migration files that should be ignored.--commit: Perform agit commitfor the changes after moving file old -> new.--verbose: Verbose command execution.
Usage:
$ auto_migration_resolver --app-name my_app --commit --verbose
Output
...
Using Static migration resolver
CLI command: migration_resolver
Fix migrations by providing the following:
--app-name: The app_name of the Django application.--last: Last migration file of the remote that should be the seed of the conflicted migrations with or without the suffix.--conflict: The migration file which needs to be reseeded from the last migration file.--commit: Perform agit commitfor the changes after moving file old -> new.--verbose: Verbose command execution.
Usage:
$ migration_resolver --app-name my_app --last 0010_auto_20200115_1632 --conflict 0008_auto_20200114_5438 --commit --verbose
Output
Fixing migrations...
Updating the conflicting migration file 0008_auto_20200114_5438.py
Succefully updated: 0008_auto_20200114_5438.py.
Renaming the migration file from 0008_auto_20200114_5438.py to 0011_auto_20200114_5438.py
Successfully renamed the migration file.
[my-test-branch c18fca41e] Resolved migration conflicts for 0008_auto_20200114_5438.py → 0011_auto_20200114_5438.py
1 file changed, 1 insertion(+), 1 deletion(-)
rename my_app/migrations/{0008_auto_20200114_5438.py => 0011_auto_20200114_5438.py} (99%)
For more options
$ migration_resolver --help
usage: migration_resolver [-h] [--auto-detect] [--verbose] --app-name APP_NAME --last LAST --conflict CONFLICT [--commit]
Resolve duplicate migration nodes.
optional arguments:
-h, --help show this help message and exit
--auto-detect Auto-detect and fix migration errors. (Not supported)
--verbose Verbose output
--app-name APP_NAME App Name
--last LAST The glob/full name of the final migration file.
--conflict CONFLICT The glob/full name of the final migration file with the conflict.
--commit Commit the changes made.
Using vsc (git/mercurial) when the remote has a migration files that conflict with previous migrations you have locally.
TODO:
- Auto detect and resolve errors with migration nodes.
- Speed up execution using async/await for handling reading nodes.
- Add support for database unapply migration for case of applied migrations.
- Add support to rollback any changes if there are failures in the chain of operation.
- VCS support right now only git is supported (extend to mercurial).
- Document Auto migration strategies.
Metadata
Release files for django-migration-resolver-hook 0.2.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-migration-resolver-hook-0.2.8.tar.gz | 10.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_migration_resolver_hook-0.2.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.0 kB
Release files / django-migration-resolver-hook-0.2.8.tar.gz
| Download URL | django-migration-resolver-hook-0.2.8.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ba120a6b4b72428a1453a08c606266a90aa217c6d35c58320ea77f722ec230a
|
|
BLAKE2b-256 checksum How to use checksums |
9cb498ea5d9e0b1633d3f78612f5f25ad60479f16df2d666deffa30e264318fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.8
|
Release files / django_migration_resolver_hook-0.2.8-py3-none-any.whl
| Download URL | django_migration_resolver_hook-0.2.8-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5961c60eb4ea05a369e0d6d0bad35bc49c31265befc0405c1bc8bd0acbcc2a81
|
|
BLAKE2b-256 checksum How to use checksums |
f1ffbcdfc021b3d46e89bf1a0ec357d871d89549c3da7cda6a5b06d05c68964e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.8
|
Security for django-migration-resolver-hook 0.2.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.