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]
Metadata
Release files for django-data-migrations 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-data-migrations-0.0.3.tar.gz | 13.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_data_migrations-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.0 kB
Release files / django-data-migrations-0.0.3.tar.gz
| Download URL | django-data-migrations-0.0.3.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e638b53087709e2ce07eb1b511f8387ce6b21b9ce5252dc4428ca5d2056b319e
|
|
BLAKE2b-256 checksum How to use checksums |
008f188d13632d7ac623248c255626e934838fef5f6e5d44a0531e5e85c561e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Release files / django_data_migrations-0.0.3-py3-none-any.whl
| Download URL | django_data_migrations-0.0.3-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db7d511757c5df696d377e169d3b284aae124c173db107aac066b74a7360d4b7
|
|
BLAKE2b-256 checksum How to use checksums |
16112c8d39272cd21b0f5107cb138b5ca2501ca8decd21038dbc465193b57724
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|