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 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
-
Install the python package.
pip install git+https://github.com/powlo/django-migrant@master -
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/--interpreterswitch:python -m django_migrant install . -i ./myvenv/bin/python -
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
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.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfcfd180b08da884f5cc1197faabf4b4b7cbd4b55463f3a84431982c129a0a50
|
|
| MD5 |
47db84ed0b4061a1fd31d2ac8cce3480
|
|
| BLAKE2b-256 |
5ebcd68111453ca647a845a7f0b4a699d893d94c78533a50df94f260b3220edc
|
Provenance
The following attestation bundles were made for django_migrant-0.0.6.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.6.tar.gz -
Subject digest:
bfcfd180b08da884f5cc1197faabf4b4b7cbd4b55463f3a84431982c129a0a50 - Sigstore transparency entry: 206216057
- Sigstore integration time:
-
Permalink:
powlo/django-migrant@7260fff2847b9b4f962dd33203888bcdc2370c23 -
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@7260fff2847b9b4f962dd33203888bcdc2370c23 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2072ed2cc0aaee370b32c83655f9798565c308909599a9964e524eebbf34e2bf
|
|
| MD5 |
c49bfcf83d652acf9ed6bc8d5416add9
|
|
| BLAKE2b-256 |
86341fde5b290c9ea2b2bf8a14077c3cd0cd1dc668456cf7dcaa024250d37578
|
Provenance
The following attestation bundles were made for django_migrant-0.0.6-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.6-py3-none-any.whl -
Subject digest:
2072ed2cc0aaee370b32c83655f9798565c308909599a9964e524eebbf34e2bf - Sigstore transparency entry: 206216059
- Sigstore integration time:
-
Permalink:
powlo/django-migrant@7260fff2847b9b4f962dd33203888bcdc2370c23 -
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@7260fff2847b9b4f962dd33203888bcdc2370c23 -
Trigger Event:
push
-
Statement type: