django-phased-migrations
Minimal external library to support phased migrations for rolling deploys with two (or more) Django backends sharing one Postgres database.
The library does not override Django’s built-in migrate command.
Instead, it ships its own management commands that use Django’s public
migration APIs.
Installation
pip install django-phased-migrations
Add to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_phased_migrations",
]
Migration classification rule
- Contract migrations: migration module name ends with
_contract(i.e. filename ends with*_contract.py) - Expand migrations: everything else (including all historical migrations without suffix)
Example:
myapp/migrations/0012_drop_old_column_contract.py→ contractmyapp/migrations/0011_add_new_column.py→ expand
Commands
-
manage.py migrate_expand- Applies only expand migrations.
- Never applies contract migrations.
- Warns if contract migrations are pending.
- Fails fast if reaching an expand target would require applying a contract migration.
-
manage.py migrate_contract- Applies only contract migrations.
- Fails fast if it would need to apply any non-contract migration (run
migrate_expandfirst).
-
manage.py phased_migration_status- Shows what expand/contract migrations are pending (unapplied).
Recommended ops workflow (expand / deploy / contract)
- Expand
python manage.py migrate_expand
-
Deploy
- Roll deploy your new application code (both backends can run safely against the expanded schema).
-
Contract
python manage.py migrate_contract
Failure modes and guardrails
-
If an expand migration depends on a contract migration:
migrate_expandwill error explaining that a contract migration would be required.
-
If
migrate_contractwould need to apply expand migrations (e.g. you forgot to run expand first):migrate_contractwill error telling you to runmigrate_expandfirst.
Notes / constraints (v1)
- Operates on the default database connection (optionally takes
--databasefor parity with Django). - No backfill manifest/state table; use normal Django operations (
RunSQL,RunPython) or manual steps.
Metadata
Release files for django-phased-migrations 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_phased_migrations-0.2.0.tar.gz | 7.8 kB | Without provenance | Details for django_phased_migrations-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_phased_migrations-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for django_phased_migrations-0.2.0-py3-none-any.whl |
Total release size: 16.6 kB
Release files / django_phased_migrations-0.2.0.tar.gz
| Download URL | django_phased_migrations-0.2.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24941249152202e68f955345d3fc22c3ffa6efdfe5a58be8c1caf89f79ebde1f
|
|
BLAKE2b-256 checksum How to use checksums |
b8c9c1fc60c9dce39415927c57f05bf832698db579cead5edad594c3d2960a92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / django_phased_migrations-0.2.0-py3-none-any.whl
| Download URL | django_phased_migrations-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2c7ac38d410851e58d9cfe4d6b26bc1700c6eb53992e16aec344f5399fe5edbf
|
|
BLAKE2b-256 checksum How to use checksums |
58f55ea47bd94f97e07af5f7346b7149e4b4be180f9567bfe28024bb9576bca1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for django-phased-migrations 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.