Skip to main content

CLI for comparing Django migrations between two snapshots.

Project description

PyPI version Python versions License

CLI to compare Django migrations between two snapshots.

This may be useful when you need to compare migrations in the same app between different branches.

Installation

pip install django-migrations-diff

Requirements

  • Python 3.6 or higher

How to use

# show help
mdiff help

# Create migrations snapshot
mdiff <snapshot>

# Compare two snapshots
mdiff <snapshot_1> <snapshot_2>

# Compare two snapshots (get number of diffent migrations)
mdiff <snapshot_1> <snapshot_2> --number

# List of all snapshots
mdiff list

# Remove all or specific snapshots
mdiff rm all
mdiff rm <snapshot_1> <snapshot_2>

# Get current version
mdiff -v

Example

For example, you need to compare “master” and “develop” branches.

git checkout master # go to "master" branch

mdiff master # create "master" snapshot

git checkout develop # go to "develop" branch

mdiff develop # create "develop" shapshot

mdiff master develop # compare two snapshots

In output you expect to see only new migrations in “develop” branch, otherwise it means that original migrations from “master” were deleted or changed.

Yellow-labeled migration means that same migration exist in both snapshots but it was modified and now has different code.

CI/CD configuration

This package also can be used to detect new migrations in CI/CD pipelines. For example, following stage in .gitlab-ci.yml will fail if there are new migrations in current branch in comparison to master branch.

chechcheck:
  stage: tests
  script:
    - pip install django-migrations-diff==2.0.4
    - git merge-base origin/master HEAD | xargs git checkout
    - mdiff master
    - git checkout ${CI_COMMIT_REF_NAME}
    - mdiff ${CI_COMMIT_REF_NAME}
    - mdiff master ${CI_COMMIT_REF_NAME}
    - (if [[ $(mdiff master ${CI_COMMIT_REF_NAME} --number) == 0 ]]; then echo "No new migrations"; else exit 1; fi;)
  allow_failure: true

NOTE: This is not full stage descriptions, this is only example.

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-migrations-diff-2.0.4.tar.gz (8.3 kB view hashes)

Uploaded Source

Built Distribution

django_migrations_diff-2.0.4-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

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