migration safety toolkit for Django.
Project description
Django Migrations Inspector
django-migrations-inspector is an open source migration safety toolkit for Django.
Install the package from PyPI with:
python -m pip install django-migrations-inspector
Then add the Django app to INSTALLED_APPS with:
INSTALLED_APPS = [
# ...
"django_migration_inspector",
]
It is designed around four practical Django questions:
migration_inspect: Is the migration graph healthy or messy?migration_inspect risk: Are the pending migrations safe to deploy?migration_inspect audit: Which migration files in this repo deserve attention?migration_inspect rollback APP TARGET: If we need to reverse, what blocks us and what else gets touched?
How the commands work:
migration_inspectloads Django's migration graph and reports graph shape: heads, merge migrations, roots, leaves, and dependency hotspots. Add--offlineto read migration files without opening a database connection.migration_inspect riskasks Django for the pending forward migration plan, then checks those operations with safety rules for destructive schema changes, irreversible data code, raw SQL, unknown operations, and nested operations insideSeparateDatabaseAndState. This needs database state.migration_inspect audituses the same safety rules asrisk, but scans the migration history instead of only pending migrations. Add--offlinewhen you only want to review migration files on disk.migration_inspect rollback APP TARGETasks Django for the reverse plan to reachTARGET.TARGETcan be a full migration name, a unique prefix like0008, orzero. It checks reversibility, expected destructive reverse actions like dropping newly added tables or columns, and cross-app impact from migration dependencies, but it does not apply the rollback. This needs database state.
By default, inspect, risk, and audit ignore Django built-in apps and third-party apps.
Those reports focus on project apps that live inside your Django project tree rather than
everything installed in the environment.
rollback stays dependency-accurate instead of hiding external apps, because rollback safety can
depend on them.
The current implementation focuses on:
- Loading Django migration graphs into a typed internal model.
- Detecting merge nodes, multiple heads, root and leaf migrations, and dependency hotspots.
- Analyzing both pending deploy plans and historical migration files with rule-driven risk scoring.
- Simulating rollback plans with blockers, blast radius, cross-app impact, and reverse-step previews.
- Rendering deterministic text, JSON, Mermaid, and Graphviz DOT reports.
- Exposing a reusable
migration_inspectDjango management command.
Example usage:
python manage.py migration_inspect
python manage.py migration_inspect --offline
python manage.py migration_inspect --details
python manage.py migration_inspect risk
python manage.py migration_inspect risk --details
python manage.py migration_inspect audit
python manage.py migration_inspect audit --offline
python manage.py migration_inspect audit --details
python manage.py migration_inspect rollback billing 0001_initial
python manage.py migration_inspect rollback inventory zero
python manage.py migration_inspect rollback inventory zero --details
python manage.py migration_inspect rollback inventory 0001_initial --why-app catalog
python manage.py migration_inspect --json
python manage.py migration_inspect --format mermaid
python manage.py migration_inspect --format dot
python manage.py migration_inspect --app analytics
Replace billing, inventory, catalog, and analytics with app labels from your own Django project.
To expose the management command, add "django_migration_inspector" to INSTALLED_APPS.
For hosted project documentation, this repository includes an MkDocs site that can be published on
GitHub Pages or Read the Docs.
Local docs commands:
python -m pip install '.[docs]'
mkdocs serve
mkdocs build --strict
Local quality commands:
python -m pip install -e '.[dev,docs]'
ruff format .
ruff format --check .
ruff check .
mypy src tests
pytest -q
Project details
Release history Release notifications | RSS feed
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_migrations_inspector-0.1.0.tar.gz.
File metadata
- Download URL: django_migrations_inspector-0.1.0.tar.gz
- Upload date:
- Size: 53.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
544bcd866113c5ad4f661f9da1a7641ffae9ecb012a47e0ab99c2c874273edd2
|
|
| MD5 |
c155618a0e96fb33c28ed4558ceebfd7
|
|
| BLAKE2b-256 |
772cc0d8b8e212baaa68c081eee116e3776618a9cd7f2b75698247fd5531dee1
|
Provenance
The following attestation bundles were made for django_migrations_inspector-0.1.0.tar.gz:
Publisher:
release.yml on DevilsAutumn/django-migrations-inspector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_migrations_inspector-0.1.0.tar.gz -
Subject digest:
544bcd866113c5ad4f661f9da1a7641ffae9ecb012a47e0ab99c2c874273edd2 - Sigstore transparency entry: 1347949879
- Sigstore integration time:
-
Permalink:
DevilsAutumn/django-migrations-inspector@859e08cf5cf6260800ea05e18cc9a04e2c75d83f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/DevilsAutumn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@859e08cf5cf6260800ea05e18cc9a04e2c75d83f -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_migrations_inspector-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_migrations_inspector-0.1.0-py3-none-any.whl
- Upload date:
- Size: 57.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb30a9490221d1597c55e745d4f2ef3abd19639de219b7cbb3e13ff71d1004de
|
|
| MD5 |
e83c05cf7f98296e2e132b03e9366f74
|
|
| BLAKE2b-256 |
1789b522f77363a84c36fa5df1f95a3170ffcfd8925883d8dec3021b3b01a53c
|
Provenance
The following attestation bundles were made for django_migrations_inspector-0.1.0-py3-none-any.whl:
Publisher:
release.yml on DevilsAutumn/django-migrations-inspector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_migrations_inspector-0.1.0-py3-none-any.whl -
Subject digest:
bb30a9490221d1597c55e745d4f2ef3abd19639de219b7cbb3e13ff71d1004de - Sigstore transparency entry: 1347949884
- Sigstore integration time:
-
Permalink:
DevilsAutumn/django-migrations-inspector@859e08cf5cf6260800ea05e18cc9a04e2c75d83f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/DevilsAutumn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@859e08cf5cf6260800ea05e18cc9a04e2c75d83f -
Trigger Event:
push
-
Statement type: