A developer utility to auto-migrate django apps when switching git branches.
Project description
django-migrant
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? 🙂
Example
The example repository can be found at https://github.com/powlo/django-migrant-example
Installation
-
Install the python package.
pip install django-migrant -
Add django_migrant to settings.py
#settings.py INSTALLED_APPS = [ # ... "django_migrant", # ... ] -
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.
-
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_migrant-0.0.9.tar.gz.
File metadata
- Download URL: django_migrant-0.0.9.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45dfdad1b692fcee0e9705352249a12627f581b337698974640347c4b4178bf6
|
|
| MD5 |
95435010f513043766b1d9c0c9d30bea
|
|
| BLAKE2b-256 |
de0629f7bcfee9aca94a59a55dcdf73a1ee0620f5bdd16691abf703ecc7ecebe
|
Provenance
The following attestation bundles were made for django_migrant-0.0.9.tar.gz:
Publisher:
test.yml on powlo/django-migrant
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_migrant-0.0.9.tar.gz -
Subject digest:
45dfdad1b692fcee0e9705352249a12627f581b337698974640347c4b4178bf6 - Sigstore transparency entry: 211523210
- Sigstore integration time:
-
Permalink:
powlo/django-migrant@387dfe2f028652720ea5ce4bbd03ec3688bbf357 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/powlo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test.yml@387dfe2f028652720ea5ce4bbd03ec3688bbf357 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_migrant-0.0.9-py3-none-any.whl.
File metadata
- Download URL: django_migrant-0.0.9-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92c23caaa296a5328b099db91fb714b640d4022ee1b42dd341dc2bb69a702d20
|
|
| MD5 |
6295c0b9649c230eea835911ad3c7146
|
|
| BLAKE2b-256 |
6760a697ad0790fc1003b12603204d55a3c798f79070060e36a623c643d9291b
|
Provenance
The following attestation bundles were made for django_migrant-0.0.9-py3-none-any.whl:
Publisher:
test.yml on powlo/django-migrant
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_migrant-0.0.9-py3-none-any.whl -
Subject digest:
92c23caaa296a5328b099db91fb714b640d4022ee1b42dd341dc2bb69a702d20 - Sigstore transparency entry: 211523213
- Sigstore integration time:
-
Permalink:
powlo/django-migrant@387dfe2f028652720ea5ce4bbd03ec3688bbf357 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/powlo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test.yml@387dfe2f028652720ea5ce4bbd03ec3688bbf357 -
Trigger Event:
push
-
Statement type: