Skip to main content

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:

  1. migration_inspect: Is the migration graph healthy or messy?
  2. migration_inspect risk: Are the pending migrations safe to deploy?
  3. migration_inspect audit: Which migration files in this repo deserve attention?
  4. migration_inspect rollback APP TARGET: If we need to reverse, what blocks us and what else gets touched?

How the commands work:

  1. migration_inspect loads Django's migration graph and reports graph shape: heads, merge migrations, roots, leaves, and dependency hotspots. Add --offline to read migration files without opening a database connection.
  2. migration_inspect risk asks 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 inside SeparateDatabaseAndState. This needs database state.
  3. migration_inspect audit uses the same safety rules as risk, but scans the migration history instead of only pending migrations. Add --offline when you only want to review migration files on disk.
  4. migration_inspect rollback APP TARGET asks Django for the reverse plan to reach TARGET. TARGET can be a full migration name, a unique prefix like 0008, or zero. 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:

  1. Loading Django migration graphs into a typed internal model.
  2. Detecting merge nodes, multiple heads, root and leaf migrations, and dependency hotspots.
  3. Analyzing both pending deploy plans and historical migration files with rule-driven risk scoring.
  4. Simulating rollback plans with blockers, blast radius, cross-app impact, and reverse-step previews.
  5. Rendering deterministic text, JSON, Mermaid, and Graphviz DOT reports.
  6. Exposing a reusable migration_inspect Django 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_migrations_inspector-0.1.0.tar.gz (53.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_migrations_inspector-0.1.0-py3-none-any.whl (57.7 kB view details)

Uploaded Python 3

File details

Details for the file django_migrations_inspector-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django_migrations_inspector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 544bcd866113c5ad4f661f9da1a7641ffae9ecb012a47e0ab99c2c874273edd2
MD5 c155618a0e96fb33c28ed4558ceebfd7
BLAKE2b-256 772cc0d8b8e212baaa68c081eee116e3776618a9cd7f2b75698247fd5531dee1

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_migrations_inspector-0.1.0.tar.gz:

Publisher: release.yml on DevilsAutumn/django-migrations-inspector

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_migrations_inspector-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_migrations_inspector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb30a9490221d1597c55e745d4f2ef3abd19639de219b7cbb3e13ff71d1004de
MD5 e83c05cf7f98296e2e132b03e9366f74
BLAKE2b-256 1789b522f77363a84c36fa5df1f95a3170ffcfd8925883d8dec3021b3b01a53c

See more details on using hashes here.

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

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