django-data-migrations


Namedjango-data-migrations JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://github.com/philsupertramp/django-data-migration/
SummaryExtraction tool for data only django migrations
upload_time2023-07-23 14:31:30
maintainer
docs_urlNone
authorPhilipp Zettl
requires_python
licenseMIT
keywords django database migrations
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            django-data-migration
=====================

|Test dev branch|
|Pypi|

| 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. Sometimes we even create migrations in the purpose of single-time usage to move, edit, duplicate or basically modify data.

| Generally speaking, the idea behind it is clever.

| With this approach you gained the option to trigger the execution of leaf migrations prior to starting your updated application code.

.. code:: text

           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 a dedicated node in the migration tree.
| It does that, by providing a "data-only" migration graph, that can optionally be maintained automatically in parallel with the existing migration graph, or executed independently, depending on your needs.

Installation
============

Install package:

| ``pip install django-data-migrations``

| Configure package in Django settings:

.. code:: python

    INSTALLED_APPS = [
        # django apps
        'data_migration',
        # your apps
    ]

Configuration
=============

| The package is configurable using the

.. code:: python

    DATA_MIGRATION = {}

setting.

Currently supported attributes:

- ``SQUASHABLE_APPS``: a list of app(-label) names which allow squashing, you should only provide your own apps here


Usage
=====

Extended management commands:
- ``makemigrations``
- ``migrate``
- ``squashmigrations``
- ``data_migrate``

``makemigrations``
~~~~~~~~~~~~~~~~~~

.. code:: shell

    # 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

.. code:: python

    class Node:
        name = '0001_first'
        dependencies = ()
        migration_dependencies = ('testapp.0001_initial', )
        routines = [
        ]

``migrate``
~~~~~~~~~~~

.. code:: shell

    # 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



``squashmigrations``
~~~~~~~~~~~~~~~~~~~~

| App-wise squashing of data/regular migrations.

.. code:: shell

    # regular squashing of test_app migrations 0001-0015
    ./manage.py squashmigrations test_app 0001 0015

    # squash and replace test_app migrations 0001-0015 and extract data_migrations
    ./manage.py squashmigrations --extract-data-migrations test_app 0001 0015

``data_migrate``
~~~~~~~~~~~~~~~~

| Extended squashing. Allows squashing a single app, a list of apps, or all apps at once.

.. code:: shell

    # squash and replace all migrations at once
    ./manage.py data_migrate --all

    # squash and replace migrations app-wise
    ./manage.py data_migrate test_app


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

.. code:: shell

    coverage run -m pytest -v tests
    coverage [html|report]

.. |Test dev branch| image:: https://github.com/philsupertramp/django-data-migration/actions/workflows/test-dev.yml/badge.svg?branch=dev
   :target: https://github.com/philsupertramp/django-data-migration/actions/workflows/test-dev.yml

.. |Pypi| image:: https://badge.fury.io/py/django-data-migrations.svg
    :target: https://badge.fury.io/py/django-data-migrations

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/philsupertramp/django-data-migration/",
    "name": "django-data-migrations",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django,database migrations",
    "author": "Philipp Zettl",
    "author_email": "philipp.zett@godesteem.de",
    "download_url": "https://files.pythonhosted.org/packages/1c/a4/e36210c3f4c4b87dd5811f8edf73abd194df7020c91cc1ebad4dddebdeed/django-data-migrations-0.1.5.tar.gz",
    "platform": null,
    "description": "django-data-migration\n=====================\n\n|Test dev branch|\n|Pypi|\n\n| 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.\n\n| 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. Sometimes we even create migrations in the purpose of single-time usage to move, edit, duplicate or basically modify data.\n\n| Generally speaking, the idea behind it is clever.\n\n| With this approach you gained the option to trigger the execution of leaf migrations prior to starting your updated application code.\n\n.. code:: text\n\n           Missing migration?\n           /                \\\n     yes, migrate        no, continue\n           \\                /\n        restart app with new code\n\n| But on the other hand you create a new node within a already giant migration graph.\n| This is where ``django-data-migration`` comes in place. It is a drop-in replacement for regular migrations, without the need of a dedicated node in the migration tree.\n| It does that, by providing a \"data-only\" migration graph, that can optionally be maintained automatically in parallel with the existing migration graph, or executed independently, depending on your needs.\n\nInstallation\n============\n\nInstall package:\n\n| ``pip install django-data-migrations``\n\n| Configure package in Django settings:\n\n.. code:: python\n\n    INSTALLED_APPS = [\n        # django apps\n        'data_migration',\n        # your apps\n    ]\n\nConfiguration\n=============\n\n| The package is configurable using the\n\n.. code:: python\n\n    DATA_MIGRATION = {}\n\nsetting.\n\nCurrently supported attributes:\n\n- ``SQUASHABLE_APPS``: a list of app(-label) names which allow squashing, you should only provide your own apps here\n\n\nUsage\n=====\n\nExtended management commands:\n- ``makemigrations``\n- ``migrate``\n- ``squashmigrations``\n- ``data_migrate``\n\n``makemigrations``\n~~~~~~~~~~~~~~~~~~\n\n.. code:: shell\n\n    # generate data migration file\n    ./manage.py makemigrations --data-only [app_name]\n\n    # generate data migration file with readable name \"name_change\"\n    ./manage.py makemigrations --data-only [app_name] name_change\n\n    # generate empty file\n    ./manage.py makemigrations --data-only [app_name] --empty\n\n    # generate without fileheader\n    ./manage.py makemigrations --data-only [app_name] --no-header\n\nThe ``makemigrations`` command generates a file\n``[app_name]/data_migrations/[id]_[name].py`` with content like\n\n.. code:: python\n\n    class Node:\n        name = '0001_first'\n        dependencies = ()\n        migration_dependencies = ('testapp.0001_initial', )\n        routines = [\n        ]\n\n``migrate``\n~~~~~~~~~~~\n\n.. code:: shell\n\n    # apply data migration file\n    ./manage.py migrate --data-only\n\n    # revert complete data migration state\n    ./manage.py migrate --data-only zero\n\n    # revert partial data migration state\n    ./manage.py migrate --data-only 0002_some_big_change\n\n\n\n``squashmigrations``\n~~~~~~~~~~~~~~~~~~~~\n\n| App-wise squashing of data/regular migrations.\n\n.. code:: shell\n\n    # regular squashing of test_app migrations 0001-0015\n    ./manage.py squashmigrations test_app 0001 0015\n\n    # squash and replace test_app migrations 0001-0015 and extract data_migrations\n    ./manage.py squashmigrations --extract-data-migrations test_app 0001 0015\n\n``data_migrate``\n~~~~~~~~~~~~~~~~\n\n| Extended squashing. Allows squashing a single app, a list of apps, or all apps at once.\n\n.. code:: shell\n\n    # squash and replace all migrations at once\n    ./manage.py data_migrate --all\n\n    # squash and replace migrations app-wise\n    ./manage.py data_migrate test_app\n\n\nDevelopment\n===========\n\nTo develop the package further set up a local environment using the\nprovided ``./dev-requirements.txt`` file.\n\nTo run the test suite and generate a coverage report run\n\n.. code:: shell\n\n    coverage run -m pytest -v tests\n    coverage [html|report]\n\n.. |Test dev branch| image:: https://github.com/philsupertramp/django-data-migration/actions/workflows/test-dev.yml/badge.svg?branch=dev\n   :target: https://github.com/philsupertramp/django-data-migration/actions/workflows/test-dev.yml\n\n.. |Pypi| image:: https://badge.fury.io/py/django-data-migrations.svg\n    :target: https://badge.fury.io/py/django-data-migrations\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Extraction tool for data only django migrations",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://github.com/philsupertramp/django-data-migration/"
    },
    "split_keywords": [
        "django",
        "database migrations"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7094eb0dda3cae6955c083b9fb4219651d0eacea55937e5c94ea7d098f6ab7f0",
                "md5": "fedcfbce567576a977124cbc0003ca4b",
                "sha256": "d97f18946ae69188155b7923c3396de88d2575dc17b99981746dbec8d52a5b18"
            },
            "downloads": -1,
            "filename": "django_data_migrations-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fedcfbce567576a977124cbc0003ca4b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 19192,
            "upload_time": "2023-07-23T14:31:28",
            "upload_time_iso_8601": "2023-07-23T14:31:28.703417Z",
            "url": "https://files.pythonhosted.org/packages/70/94/eb0dda3cae6955c083b9fb4219651d0eacea55937e5c94ea7d098f6ab7f0/django_data_migrations-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1ca4e36210c3f4c4b87dd5811f8edf73abd194df7020c91cc1ebad4dddebdeed",
                "md5": "781aef7d6df00c128a29bddad8e27d87",
                "sha256": "246cd037d2d19b83c6a2da7e5207eeeec8a139a0e70b6b9ba54bc9cdf38f0a8a"
            },
            "downloads": -1,
            "filename": "django-data-migrations-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "781aef7d6df00c128a29bddad8e27d87",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15426,
            "upload_time": "2023-07-23T14:31:30",
            "upload_time_iso_8601": "2023-07-23T14:31:30.265147Z",
            "url": "https://files.pythonhosted.org/packages/1c/a4/e36210c3f4c4b87dd5811f8edf73abd194df7020c91cc1ebad4dddebdeed/django-data-migrations-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-23 14:31:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "philsupertramp",
    "github_project": "django-data-migration",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "django-data-migrations"
}
        
Elapsed time: 0.46633s