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 colleague'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 and a pre-rebase hook in a repository's "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.

The tool deliberately does not perform migration operations during a git rebase however, assuming the rebase goes well (🤞), it should just be a case of running ./manage.py migrate, right? 🙂

Installation

  1. Install the python package.

     pip install django-migrant
    
  2. Add django_migrant to settings.py

     #settings.py
     INSTALLED_APPS = [
         # ...
         "django_migrant",
         # ...
     ]
    
  3. Install the post-checkout hook:

     ./manage.py migrant install <destination>
    

    Eg,

     ./manage.py migrant install .
    

    ...will attempt to install the hook in the current directory.

  4. Review and adapt the hooks if necessary.

The hooks are installed assuming that the application has been added to settings.py and that the appropriate python interpreter is available when executing the hook. This should work for most users.

However, instead of adding django_migrant to your INSTALLED_APPS, you may wish to change the post-checkout script to invoke the python module directly. For example:

#.git/hooks/post-checkout
DJANGO_SETTINGS_MODULE=myproject.settings python -m django_migrant migrate

Similarly, you may wish to specify the full path to the python interpreter:

#.git/hooks/post-checkout
/home/myname/virtualenvs/myproject/bin/python ./manage.py migrant migrate

Check the hook invocation matches the nuances of your own environment.

IMPORTANT! Change the permissions on the hooks to allow them to be invoked.

Eg,

chmod +x ./.git/hooks/post-checkout
chmod +x ./.git/hooks/pre-rebase

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_migrant-0.0.8.tar.gz
  • Upload date:
  • Size: 21.5 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.8.tar.gz
Algorithm Hash digest
SHA256 6c4fb63254b82ca13818f382d0bb9f3458fd47243cebd41a5410b9572fee1de7
MD5 054fcb8ae32193cb308a22f5cf198c56
BLAKE2b-256 1748bfb650abade7313285bdc9c6b692cc4b67512162858bd76eec7a301f31c5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: django_migrant-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 18.6 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9199174960e8fd393f4cb130c0334ebd02b7cc7b834beae73bf0e65de5e0a04f
MD5 361b5ed56281a1a38c12dffa22689526
BLAKE2b-256 78f45fa7b185e2702c227fe0a7a97f2376a6c7a634c6275fb0b48f9c7ef8f0c0

See more details on using hashes here.

Provenance

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