Skip to main content

django-migrate-project

License Build Status Latest PyPI version Coverage

Django management commands for project-wide (editable) migrations.

Overview

The django-migrate-project app aims to add management commands to make running full project migrations more sane and controllable. The concept is pretty simple: first collect any unapplied migrations into per-app migration files, then review and modify as need be, and finally apply the migrations.

By staging and consolidating unapplied migrations in a way that they can be edited and reviewed before applying, more confidence is gained that a rogue migration won’t damage production tables. The collected and consolidated migrations are listed as replacements for the individual app migrations they represent so once they have been applied everything is in the same state as if the individual app migrations has been applied via ‘migrate’.

Requirements

Requires Django 1.7+ and as such Python 2.7+ as well

Installation

Simply use pip to install:

$ pip install django-migrate-project

To be of any use django-migrate-project must be added to the Django project via INSTALLED_APPS in the project settings.py file:

INSTALLED_APPS = (
    ...
    'django_migrate_project',
    ...
)

Usage

Two new management commands provide the core functionality. To gather up any unapplied migrations for the project simply run:

$ python manage.py collectmigrations

The default collection location is BASE_DIR/pending_migrations. If the project’s settings.py does not have a BASE_DIR then a directory path must be provided using the --output-dir option.

The collected migrations are grouped per-app and have the filename format of <app_label>_project.py. These files can be edited to taste in order to change the migration, the only important bit is to keep the replaces and dependencies fields in the migration the same, as those allow the bookkeeping to be kept accurate.

Collected migrations are applied via:

$ python manage.py applymigrations

The default directory path is used again if possible, otherwise the path must be provided via the --input-dir option.

Finally, migrations can be unapplied easily as well, returning the migration state to what it was before by running:

$ python manage.py applymigrations --unapply

Experimental

Starting with v0.2.0 there’s also the capability to generate project-level migrations as a way to capture monkey-patched models and other changes that shouldn’t create migrations in a third-party app.

To use this functionality, first create a top-level migrations directory with a __init__.py file to make it a Python package. Then run the following command to create any new project-level migrations (changes not present in third-party app migrations):

$ python manage.py makeprojectmigrations

Assuming there are any migrations to generate, the top-level migrations directory should now be populated and you can migrate the project using:

$ python manage.py migrateproject

As with the applymigrations command, migrateproject also has an easy unapply functionality:

$ python manage.py migrateproject --unapply

While this functionality is well covered by tests it will remain ‘experimental’ until it gets a bit more real world use.

Contributing

Contributions are welcome, just create a pull request or issue on the GitHub repository for the project.

Metadata

Release files for django-migrate-project 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-migrate-project 0.2.0
File Size Uploaded Provenance
django-migrate-project-0.2.0.tar.gz 14.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-migrate-project 0.2.0
File Interpreter ABI Platform
django-migrate-project-0.2.0.linux-x86_64.tar.gz Details

Total release size: 39.8 kB

Release files / django-migrate-project-0.2.0.tar.gz

Download URL django-migrate-project-0.2.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b78518b4681c866b286616917687903ba13b235fcdba377940aab631f9a9ec21
BLAKE2b-256 checksum
How to use checksums
d20e8967f62784b3ea2168fed8ed27545e668a3a53fc9b95c869563265b46f96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django-migrate-project-0.2.0.linux-x86_64.tar.gz

Download URL django-migrate-project-0.2.0.linux-x86_64.tar.gz
Size 25.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f0120bc3d748ebd0b548bf1f1700a66dc6e021b37949b8bc743ba45ee6b8375c
BLAKE2b-256 checksum
How to use checksums
83c19dcd902af17348da0628f23d09f4b3e1da83aac5a52492231770cb27c45c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-migrate-project 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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