Skip to main content

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

Project description

django-migrant

Github Branch Status Coverage Pypi Version 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.

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.7.tar.gz (21.2 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.7-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_migrant-0.0.7.tar.gz
  • Upload date:
  • Size: 21.2 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.7.tar.gz
Algorithm Hash digest
SHA256 76e66db8f51a9ca3588f4eecbf20767d06bb9114185db69b0bea58f6fdf47d4e
MD5 f07818bb19e057098f582bb239e68c22
BLAKE2b-256 209179d3a04af09390b5787af661df0786e0c886c8603c79912b610550c704e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_migrant-0.0.7.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.7-py3-none-any.whl.

File metadata

  • Download URL: django_migrant-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 18.5 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 dfab8883492b9947df739acf2718a1b5a444efc92afedd25027e501b5a2f9061
MD5 645a8856ab11706ae18f80a393f17d83
BLAKE2b-256 e52a91778e55bb07fb60f9bca846bc2e9a4f9bb125aff6d737bd30c0909f3205

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_migrant-0.0.7-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