Extraction tool for data only django migrations
Project description
django-data-migration
Developing and maintaining a django project over many years can start to become a constant fight against time consuming tasks including execution of a test suite, recreation of a local environment or setting up a project in a new environment.
Due to different flavors of deployment and/or different approaches within the same working environment migration files of long running django applications tent to be bloated and contain unnecessary code. Which was at that time implemented to move, edit, duplicate or basically modify data. And the idea behind it is also clever.
With this approach you gained the option to trigger migration of leaf migrations prior to starting your updated application code.
Missing migration?
/ \
yes, migrate no, continue
\ /
restart app with new code
But on the other hand you create a new node within a already giant migration graph.
This is where django-data-migration comes in place. It is a drop-in replacement for regular migrations, without the need of an dedicated node in the migration tree.
Installation
Install package:
pip install django-data-migrations
Configure package in Django settings:
INSTALLED_APPS = [
# django apps
'data_migration',
# your apps
]
Usage
Extended management commands: - makemigrations - migrate - squashmigrations
makemigrations
# generate data migration file
./manage.py makemigrations --data-only [app_name]
# generate data migration file with readable name "name_change"
./manage.py makemigrations --data-only [app_name] name_change
# generate empty file
./manage.py makemigrations --data-only [app_name] --empty
# generate without fileheader
./manage.py makemigrations --data-only [app_name] --no-header
The makemigrations command generates a file [app_name]/data_migrations/[id]_[name].py with content like
class Node:
name = '0001_first'
dependencies = ()
migration_dependencies = ('testapp.0001_initial', )
routines = [
]
migrate
# apply data migration file ./manage.py migrate --data-only # revert complete data migration state ./manage.py migrate --data-only zero # revert partial data migration state ./manage.py migrate --data-only 0002_some_big_change
Development
To develop the package further set up a local environment using the provided ./dev-requirements.txt file.
To run the test suite and generate a coverage report run
coverage run -m pytest -v tests
coverage [html|report]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-data-migrations-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc0974a1ecfa17c44d9ec1afd1b9f8cc5666f11226f98af92e06527326d64a2d |
|
MD5 | 09021936b930ef5d2e140fb26bc8da33 |
|
BLAKE2b-256 | 0d05483055f87dbdc0d89f75767db9e3cfcdb3fe3be9a935efc9d87487dd46bf |
Close
Hashes for django_data_migrations-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc31ef3c17bbffe49e59ecdbf3e0171abe565c12d02f3fdee74824d2797df366 |
|
MD5 | 8abf8a2c1128d0dfbf0e3bcc1b9ca79f |
|
BLAKE2b-256 | 6a8f7c34ef7bee1f1de9c2efe9ae6a340cd28f23f86e1b9dba2b3ff9c08fd487 |