Skip to main content

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 → contract
  • myapp/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_expand first).
  • 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_expand will error explaining that a contract migration would be required.
  • If migrate_contract would need to apply expand migrations (e.g. you forgot to run expand first):

    • migrate_contract will error telling you to run migrate_expand first.

Notes / constraints (v1)

  • Operates on the default database connection (optionally takes --database for parity with Django).
  • No backfill manifest/state table; use normal Django operations (RunSQL, RunPython) or manual steps.

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)

Source distribution for django-phased-migrations 0.2.0
File Size Uploaded
django_phased_migrations-0.2.0.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-phased-migrations 0.2.0
File Interpreter ABI Platform
django_phased_migrations-0.2.0-py3-none-any.whl Python 3 none any Details

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}

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page