Skip to main content

Phased Django migrations for rolling deploys (expand/contract).

Project description

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-migration

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.

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_phased_migrations-0.1.0.tar.gz (7.9 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.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_phased_migrations-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.5 {"installer":{"name":"uv","version":"0.11.5","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.1.0.tar.gz
Algorithm Hash digest
SHA256 71ae4f0bb28b357a3db56aa6f5aa646e440c3561a6382d9456ab532ccf04da0d
MD5 1af1352a8b239649f471167faf444e14
BLAKE2b-256 055c69191bc79821663cc87eb899db4196131659836f6bae1f6208e80717d2a4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_phased_migrations-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.5 {"installer":{"name":"uv","version":"0.11.5","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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c8a7451f78416d3a663eb29c787b77ab0f67937d148473708e7377a8653fccd
MD5 7c3cb14af0e9ee085d254595825fe9eb
BLAKE2b-256 c678a112122639da288a9975e551b60e90fe7599929b2406f8aff062ff188901

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