Skip to main content

A developer utility to auto-migrate django apps when switching git branches.

Project description

django-migrant

Branch Status Coverage

GitHub License

django-migrant is a tool that allows developers to automatically migrate their development database when switching from one git branch to another. A common use case is when asked to run a collegue's branch. With django-migrant you no longer need to figure out which migrations need to be rolled back in order to then apply another branch's migrations.

[!IMPORTANT] The tool relies on proper reverse migrations having been written!

Requirements:

  • A django project, version controlled using git, with database migrations.

How it works.

django-migrant will create a post-checkout hook in a repositories "hooks" directory.

When you checkout a branch the hook will determine which django migrations need to be rolled back, go to the previous branch and roll back, then return to your target branch and migrate forwards.

It will track the changes needed by creating a .migrant directory containing a nodes.json.

Installation

  1. Install the python package.

     pip install git+https://github.com/powlo/django-migrant@master
    
  2. Install the post-checkout hook:

     python -m django_migrant install <destination> [-i <interpreter>]
    

    Eg,

     python -m django_migrant install .
    

    Will attempt to install the hook in the current directory.

    The interpreter used by the hook can be configured using the optional -i / --interpreter switch:

     python -m django_migrant install . -i ./myvenv/bin/python
    
  3. IMPORTANT! Read and verify the post-checkout hook and change permissions to allow it to be invoked.

    Eg,

     cd <mydjangoproject>
     chmod +x ./.git/hooks/post-checkout
    

If you wish you can specify the package as a django app:

# settings.py
INSTALLED_APPS = [
    # ...
    "django_migrant",
    # ...
]

And then change the invocation to use django admin command.

Eg,

#!/bin/bash
# .git/hooks/post-checkout

# ...
if [ "$is_branch_checkout" == "1" ]; then
    ./manage.py django_migrant migrate # <--- here
fi

(But this doesn't change the tool's behaviour.)

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_migrant-0.0.6.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_migrant-0.0.6-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file django_migrant-0.0.6.tar.gz.

File metadata

  • Download URL: django_migrant-0.0.6.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_migrant-0.0.6.tar.gz
Algorithm Hash digest
SHA256 bfcfd180b08da884f5cc1197faabf4b4b7cbd4b55463f3a84431982c129a0a50
MD5 47db84ed0b4061a1fd31d2ac8cce3480
BLAKE2b-256 5ebcd68111453ca647a845a7f0b4a699d893d94c78533a50df94f260b3220edc

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_migrant-0.0.6.tar.gz:

Publisher: test.yml on powlo/django-migrant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_migrant-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: django_migrant-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_migrant-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2072ed2cc0aaee370b32c83655f9798565c308909599a9964e524eebbf34e2bf
MD5 c49bfcf83d652acf9ed6bc8d5416add9
BLAKE2b-256 86341fde5b290c9ea2b2bf8a14077c3cd0cd1dc668456cf7dcaa024250d37578

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_migrant-0.0.6-py3-none-any.whl:

Publisher: test.yml on powlo/django-migrant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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