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.

Download files

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

Source Distribution

django_phased_migrations-0.2.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

django_phased_migrations-0.2.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file django_phased_migrations-0.2.0.tar.gz.

File metadata

  • Download URL: django_phased_migrations-0.2.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for django_phased_migrations-0.2.0.tar.gz
Algorithm Hash digest
SHA256 24941249152202e68f955345d3fc22c3ffa6efdfe5a58be8c1caf89f79ebde1f
MD5 72544a85fa412384f961582dc4a95b8e
BLAKE2b-256 b8c9c1fc60c9dce39415927c57f05bf832698db579cead5edad594c3d2960a92

See more details on using hashes here.

File details

Details for the file django_phased_migrations-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_phased_migrations-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for django_phased_migrations-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c7ac38d410851e58d9cfe4d6b26bc1700c6eb53992e16aec344f5399fe5edbf
MD5 52d0c7d5b2ede19606d9444f224b28dc
BLAKE2b-256 58f55ea47bd94f97e07af5f7346b7149e4b4be180f9567bfe28024bb9576bca1

See more details on using hashes here.

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