Skip to main content

Resolve migration conflicts.

Project description

django-migration-resolver-hook

Django Migration resolver ensures that migration files always stays ordered regardless of remote changes.

Table of Contents

  1. Installation

  2. Usage

    i. Use Case

    ii. Auto migration resolver

    iii. Static migration resolver

Installation

$ pip install django-migration-resolver-hook==0.0.5
Poetry
poetry add -D django-migration-resolver-hook==0.0.5
Using extras
setup(
    ...
    extras_require={
        'development': [
            ...
            'django-migration-resolver-hook==0.0.5',
            ...
        ]
    },
)

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:


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 a git commit for the changes after moving file old -> new.
  • --verbose: Verbose command execution.
Usage:
$ auto_migration_resolver --app-name my_app --commit --verbose
Output
...

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 a git commit for 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.
  • 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).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-migration-resolver-hook-0.1.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-migration-resolver-hook-0.1.0.tar.gz.

File metadata

  • Download URL: django-migration-resolver-hook-0.1.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for django-migration-resolver-hook-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b437671c6241f4b438a731ad356e0d10cc43cc0a614ac5b0b33547cf15c785c7
MD5 247be400bdb80c75578f8eaf14ce8b89
BLAKE2b-256 845e670a8862eee097b5723bc9c596a57c738c869f903c7e573f07021bc9b14a

See more details on using hashes here.

Provenance

File details

Details for the file django_migration_resolver_hook-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_migration_resolver_hook-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for django_migration_resolver_hook-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 812e40aa7c32b1731dc71d98c449f772658ba34e550079d01e6e8422cbd20b1c
MD5 4b61ec7dd36805ac708b56956d0b83f4
BLAKE2b-256 6cf036ff792af48becfbca4bcee7bc1c50d3da8439a7801df94b5eb77de7f4ed

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page