django-squash


Namedjango-squash JSON
Version 0.0.12 PyPI version JSON
download
home_pageNone
SummaryA migration squasher that doesn't care how Humpty Dumpty was put together.
upload_time2024-11-05 11:27:47
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords django migration squashing squash
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://img.shields.io/pypi/v/django-squash.svg?style=flat
    :alt: Supported PyPi Version
    :target: https://pypi.python.org/pypi/django-squash

.. image:: https://img.shields.io/pypi/pyversions/django-squash.svg
    :alt: Supported Python versions
    :target: https://pypi.python.org/pypi/django-squash

.. image:: https://img.shields.io/pypi/djversions/django-squash.svg
    :alt: Supported Django versions
    :target: https://pypi.org/project/django-squash/

.. image:: https://codecov.io/gh/kingbuzzman/django-squash/branch/master/graph/badge.svg
    :alt: Coverage
    :target: https://codecov.io/gh/kingbuzzman/django-squash

.. image:: https://img.shields.io/pypi/dm/django-squash
   :alt: PyPI - Downloads
   :target: https://pypistats.org/packages/django-squash

django-squash
========================

"django-squash" is a migration enhancement built on top of Django_'s standard migration classes. It aims to eliminate bloat and slowness in migration processes by replacing certain commands. The vision and architecture of Django migrations remain unchanged.

Before using "django-squash," it's important to understand the normal Django ``makemigrations`` and ``squashmigrations`` commands. Migration files consist of operations that may or may not affect the database table for a model. "elidable" operations can be eliminated when squashing migrations, while "non-elidable" operations cannot. Best way to think about the word "elidable" is to simply think "forgetable" or "disgardable" -- can this operation be disgarded once it's been ran?

The package introduces a command named ``squash_migrations`` as an alternative to Django's ``squashmigrations``. This command minimizes the number of operations needed to build the database's schema, resulting in faster testing pipelines and deployments, especially in scenarios with multiple tenants.

The catch lies in proper usage of elidable vs. non-elidable operations and the requirement that databases must not fall behind to the point where eliminated migration operations are needed. The ``squash_migrations`` command removes all elidable operations and preserves non-elidable ones.

It's crucial to run the ``squash_migrations`` command once per release after cutting the release. All databases must be on the current release, the prior release, or somewhere in between. Databases before the prior release cannot directly upgrade to the current release; they must first apply the prior release's migrations and then the current release's minimal operations.

This approach is not a tutorial on migration strategy but emphasizes the need for understanding multi-app systems, avoiding circular dependencies, and designing efficient migration processes. The tool is developed based on experience and frustration, aiming to automate and improve the migration squashing process.

You can read more about our motivation_ to creating this tool.

Setup
~~~~~~~~~~~~~~~~~~~~~~~~

1. ``pip install django-squash``

2. Add ``django_squash`` to your ``INSTALLED_APPS``.

   (optional) There are some settings_ you can customize

3. Run ``./manage.py squash_migrations`` once *after* each release

4. Profit!


Developing
~~~~~~~~~~~~~~~~~~~~~~~~

1. clone the repo

2. ``cd`` into repo

3. (optional) run inside ``docker`` environment that way you can change the python version quickly and iterate faster

.. code-block:: shell

    docker run --rm -it -v .:/app -v django-squash-pip-cache:/root/.cache/pip -e PYTHONDONTWRITEBYTECODE=1 python:3.12 bash -c "cd app; pip install -e .[test,lint]; echo \"alias linters=\\\"echo '> isort'; isort .; echo '> black'; black .; echo '> ruff'; ruff check .;echo '> flake8'; flake8 .; echo '> rst-lint'; rst-lint README.rst docs/*\\\"\" >> ~/.bash_profile; printf '\n\n\nrun **pytest** to run tests, **linters** to run linters\n\n'; exec bash --init-file ~/.bash_profile"

Alternatively, you can also create a virtual environment and run

.. code-block:: shell

    python3 -m venv venv

.. code-block:: shell

    source venv/bin/activate

.. code-block:: shell

    pip install -e '.[test]'

4. Run tests

.. code-block:: shell

    pytest

5. Before making a commit, make sure that the formatter and linter tools do not detect any issues.

.. code-block:: shell

    isort .
    black .
    flake8 .
    ruff check .
    rst-lint .

.. _Django: http://djangoproject.com
.. _`settings`: docs/settings.rst
.. _`motivation`: docs/motivation.rst

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "django-squash",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "django, migration, squashing, squash",
    "author": null,
    "author_email": "Javier Buzzi <buzzi.javier@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/5a/b1/707c7ce29373bb1a7df61fb85bed30fd4a2ce7a1c9192d3ea4d7cea94efe/django_squash-0.0.12.tar.gz",
    "platform": "any",
    "description": ".. image:: https://img.shields.io/pypi/v/django-squash.svg?style=flat\n    :alt: Supported PyPi Version\n    :target: https://pypi.python.org/pypi/django-squash\n\n.. image:: https://img.shields.io/pypi/pyversions/django-squash.svg\n    :alt: Supported Python versions\n    :target: https://pypi.python.org/pypi/django-squash\n\n.. image:: https://img.shields.io/pypi/djversions/django-squash.svg\n    :alt: Supported Django versions\n    :target: https://pypi.org/project/django-squash/\n\n.. image:: https://codecov.io/gh/kingbuzzman/django-squash/branch/master/graph/badge.svg\n    :alt: Coverage\n    :target: https://codecov.io/gh/kingbuzzman/django-squash\n\n.. image:: https://img.shields.io/pypi/dm/django-squash\n   :alt: PyPI - Downloads\n   :target: https://pypistats.org/packages/django-squash\n\ndjango-squash\n========================\n\n\"django-squash\" is a migration enhancement built on top of Django_'s standard migration classes. It aims to eliminate bloat and slowness in migration processes by replacing certain commands. The vision and architecture of Django migrations remain unchanged.\n\nBefore using \"django-squash,\" it's important to understand the normal Django ``makemigrations`` and ``squashmigrations`` commands. Migration files consist of operations that may or may not affect the database table for a model. \"elidable\" operations can be eliminated when squashing migrations, while \"non-elidable\" operations cannot. Best way to think about the word \"elidable\" is to simply think \"forgetable\" or \"disgardable\" -- can this operation be disgarded once it's been ran?\n\nThe package introduces a command named ``squash_migrations`` as an alternative to Django's ``squashmigrations``. This command minimizes the number of operations needed to build the database's schema, resulting in faster testing pipelines and deployments, especially in scenarios with multiple tenants.\n\nThe catch lies in proper usage of elidable vs. non-elidable operations and the requirement that databases must not fall behind to the point where eliminated migration operations are needed. The ``squash_migrations`` command removes all elidable operations and preserves non-elidable ones.\n\nIt's crucial to run the ``squash_migrations`` command once per release after cutting the release. All databases must be on the current release, the prior release, or somewhere in between. Databases before the prior release cannot directly upgrade to the current release; they must first apply the prior release's migrations and then the current release's minimal operations.\n\nThis approach is not a tutorial on migration strategy but emphasizes the need for understanding multi-app systems, avoiding circular dependencies, and designing efficient migration processes. The tool is developed based on experience and frustration, aiming to automate and improve the migration squashing process.\n\nYou can read more about our motivation_ to creating this tool.\n\nSetup\n~~~~~~~~~~~~~~~~~~~~~~~~\n\n1. ``pip install django-squash``\n\n2. Add ``django_squash`` to your ``INSTALLED_APPS``.\n\n   (optional) There are some settings_ you can customize\n\n3. Run ``./manage.py squash_migrations`` once *after* each release\n\n4. Profit!\n\n\nDeveloping\n~~~~~~~~~~~~~~~~~~~~~~~~\n\n1. clone the repo\n\n2. ``cd`` into repo\n\n3. (optional) run inside ``docker`` environment that way you can change the python version quickly and iterate faster\n\n.. code-block:: shell\n\n    docker run --rm -it -v .:/app -v django-squash-pip-cache:/root/.cache/pip -e PYTHONDONTWRITEBYTECODE=1 python:3.12 bash -c \"cd app; pip install -e .[test,lint]; echo \\\"alias linters=\\\\\\\"echo '> isort'; isort .; echo '> black'; black .; echo '> ruff'; ruff check .;echo '> flake8'; flake8 .; echo '> rst-lint'; rst-lint README.rst docs/*\\\\\\\"\\\" >> ~/.bash_profile; printf '\\n\\n\\nrun **pytest** to run tests, **linters** to run linters\\n\\n'; exec bash --init-file ~/.bash_profile\"\n\nAlternatively, you can also create a virtual environment and run\n\n.. code-block:: shell\n\n    python3 -m venv venv\n\n.. code-block:: shell\n\n    source venv/bin/activate\n\n.. code-block:: shell\n\n    pip install -e '.[test]'\n\n4. Run tests\n\n.. code-block:: shell\n\n    pytest\n\n5. Before making a commit, make sure that the formatter and linter tools do not detect any issues.\n\n.. code-block:: shell\n\n    isort .\n    black .\n    flake8 .\n    ruff check .\n    rst-lint .\n\n.. _Django: http://djangoproject.com\n.. _`settings`: docs/settings.rst\n.. _`motivation`: docs/motivation.rst\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A migration squasher that doesn't care how Humpty Dumpty was put together.",
    "version": "0.0.12",
    "project_urls": {
        "homepage": "https://github.com/kingbuzzman/django-squash"
    },
    "split_keywords": [
        "django",
        " migration",
        " squashing",
        " squash"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c195e9a56395fd503b95ad2365c5fcefd3c3b387d3b7c02784e290ee674964e2",
                "md5": "a67478d30a5ed21b8fea282ef491882f",
                "sha256": "92c5958be474e1897b210ddd7f2ef180d9081413a8ec4450c88afb11b033b409"
            },
            "downloads": -1,
            "filename": "django_squash-0.0.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a67478d30a5ed21b8fea282ef491882f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 20250,
            "upload_time": "2024-11-05T11:27:45",
            "upload_time_iso_8601": "2024-11-05T11:27:45.365963Z",
            "url": "https://files.pythonhosted.org/packages/c1/95/e9a56395fd503b95ad2365c5fcefd3c3b387d3b7c02784e290ee674964e2/django_squash-0.0.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ab1707c7ce29373bb1a7df61fb85bed30fd4a2ce7a1c9192d3ea4d7cea94efe",
                "md5": "37cde0b9218586fd28636c76535cc3d6",
                "sha256": "01da1bb7a05555d2cd5b9a119e6622049981c33e40bb2527c633e4ff2902d9be"
            },
            "downloads": -1,
            "filename": "django_squash-0.0.12.tar.gz",
            "has_sig": false,
            "md5_digest": "37cde0b9218586fd28636c76535cc3d6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 26796,
            "upload_time": "2024-11-05T11:27:47",
            "upload_time_iso_8601": "2024-11-05T11:27:47.047413Z",
            "url": "https://files.pythonhosted.org/packages/5a/b1/707c7ce29373bb1a7df61fb85bed30fd4a2ce7a1c9192d3ea4d7cea94efe/django_squash-0.0.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-05 11:27:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kingbuzzman",
    "github_project": "django-squash",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-squash"
}
        
Elapsed time: 4.89032s