Name | django-safemigrate JSON |
Version |
4.2
JSON |
| download |
home_page | |
Summary | Safely run migrations before deployment |
upload_time | 2023-12-13 14:45:11 |
maintainer | |
docs_url | None |
author | Ryan Hiebert |
requires_python | >=3.8 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
===========================================================
django-safemigrate: Safely run migrations before deployment
===========================================================
.. image:: https://img.shields.io/pypi/v/django-safemigrate.svg
:target: https://pypi.org/project/django-safemigrate/
:alt: Latest Version
.. image:: https://github.com/aspiredu/django-safemigrate/workflows/Build/badge.svg
:target: https://github.com/aspiredu/django-safemigrate/actions/
:alt: Build status
.. image:: https://codecov.io/gh/aspiredu/django-safemigrate/branch/master/graph/badge.svg
:target: https://codecov.io/gh/aspiredu/django-safemigrate
:alt: Code Coverage
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
:alt: Code style: black
|
django-safemigrate adds a ``safemigrate`` command to Django
to allow for safely running a migration command when deploying.
Usage
=====
Install ``django-safemigrate``, then add this to the
``INSTALLED_APPS`` in the settings file:
.. code-block:: python
INSTALLED_APPS = [
# ...
"django_safemigrate.apps.SafeMigrateConfig",
]
Then mark any migration that may be run
during a pre-deployment stage,
such as a migration to add a column.
.. code-block:: python
from django_safemigrate import Safe
class Migration(migrations.Migration):
safe = Safe.before_deploy
At this point you can run the ``safemigrate`` Django command
to run the migrations, and only these migrations will run.
However, if migrations that are not safe to run before
the code is deployed are dependencies of this migration,
then these migrations will be blocked, and the safemigrate
command will fail with an error.
When the code is fully deployed, just run the normal ``migrate``
Django command, which still functions normally.
For example, you could add the command to the release phase
for your Heroku app, and the safe migrations will be run
automatically when the new release is promoted.
Safety Options
==============
There are three options for the value of the
``safe`` property of the migration.
* ``Safe.before_deploy``
This migration is only safe to run before the code change is deployed.
For example, a migration that adds a new field to a model.
* ``Safe.after_deploy``
This migration is only safe to run after the code change is deployed.
This is the default that is applied if no ``safe`` property is given.
For example, a migration that removes a field from a model.
* ``Safe.always``
This migration is safe to run before *and* after
the code change is deployed.
For example, a migration that changes the ``help_text`` of a field.
Pre-commit Hook
===============
To get the most from django-safemigrate,
it is important to make sure that all migrations
are marked with the appropriate ``safe`` value.
To help with this, we provide a hook for use with ``pre-commit``.
`Install and configure pre-commit`_,
then add this to the ``repos`` key of your ``.pre-commit-config.yaml``:
.. code-block:: yaml
repos:
- repo: https://github.com/aspiredu/django-safemigrate
rev: "4.2"
hooks:
- id: check
.. _Install and configure pre-commit: https://pre-commit.com/
Nonstrict Mode
==============
Under normal operation, if there are migrations
that must run before the deployment that depend
on any migration that is marked to run after deployment
(or is not marked),
the command will raise an error to indicate
that there are protected migrations that
should have already been run, but have not been,
and are blocking migrations that are expected to run.
In development, however, it is common that these
would accumulate between developers,
and since it is acceptable for there to be downtime
during the transitional period in development,
it is better to allow the command to continue without raising.
To enable nonstrict mode, add the ``SAFEMIGRATE`` setting:
.. code-block:: python
SAFEMIGRATE = "nonstrict"
In this mode ``safemigrate`` will run all the migrations
that are not blocked by any unsafe migrations.
Any remaining migrations can be run after the fact
using the normal ``migrate`` Django command.
Contributing
============
To get started contributing, you'll want to clone the repository,
install dependencies via `poetry <https://python-poetry.org/>`_,
and set up `pre-commit <https://pre-commit.com/>`_.
.. code-block:: bash
git clone git@github.com:aspiredu/django-safemigrate.git
cd django-safemigrate
poetry install
pre-commit install
To run the tests use:
.. code-block:: bash
poetry run tox
To publish a new version:
1. Find and replace all instances of the previous version with the new version.
2. Commit and push that to origin.
3. Tag the commit with the new version ``git tag 1.0`` and push that to origin.
4. Create the
`new release <https://github.com/aspiredu/django-safemigrate/releases/new>`_
on GitHub.
5. Publish the new version to PyPI with ``poetry publish``.
See `Poetry's docs
<https://python-poetry.org/docs/repositories/#configuring-credentials>`_
on how to configure your local environment to publish to PyPI. Key your PyPI
token to only django-safemigrate.
.. code-block:: bash
poetry config pypi-token.pypi <my-token>
Raw data
{
"_id": null,
"home_page": "",
"name": "django-safemigrate",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "Ryan Hiebert",
"author_email": "ryan@aspiredu.com",
"download_url": "https://files.pythonhosted.org/packages/b5/86/542534fe74f9aeb99716d63646f91c7965bcd5cc2772f4d2d27b59c4b829/django_safemigrate-4.2.tar.gz",
"platform": null,
"description": "===========================================================\ndjango-safemigrate: Safely run migrations before deployment\n===========================================================\n\n.. image:: https://img.shields.io/pypi/v/django-safemigrate.svg\n :target: https://pypi.org/project/django-safemigrate/\n :alt: Latest Version\n\n.. image:: https://github.com/aspiredu/django-safemigrate/workflows/Build/badge.svg\n :target: https://github.com/aspiredu/django-safemigrate/actions/\n :alt: Build status\n\n.. image:: https://codecov.io/gh/aspiredu/django-safemigrate/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/aspiredu/django-safemigrate\n :alt: Code Coverage\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/ambv/black\n :alt: Code style: black\n\n|\n\ndjango-safemigrate adds a ``safemigrate`` command to Django\nto allow for safely running a migration command when deploying.\n\nUsage\n=====\n\nInstall ``django-safemigrate``, then add this to the\n``INSTALLED_APPS`` in the settings file:\n\n.. code-block:: python\n\n INSTALLED_APPS = [\n # ...\n \"django_safemigrate.apps.SafeMigrateConfig\",\n ]\n\nThen mark any migration that may be run\nduring a pre-deployment stage,\nsuch as a migration to add a column.\n\n.. code-block:: python\n\n from django_safemigrate import Safe\n\n class Migration(migrations.Migration):\n safe = Safe.before_deploy\n\nAt this point you can run the ``safemigrate`` Django command\nto run the migrations, and only these migrations will run.\nHowever, if migrations that are not safe to run before\nthe code is deployed are dependencies of this migration,\nthen these migrations will be blocked, and the safemigrate\ncommand will fail with an error.\n\nWhen the code is fully deployed, just run the normal ``migrate``\nDjango command, which still functions normally.\nFor example, you could add the command to the release phase\nfor your Heroku app, and the safe migrations will be run\nautomatically when the new release is promoted.\n\nSafety Options\n==============\n\nThere are three options for the value of the\n``safe`` property of the migration.\n\n* ``Safe.before_deploy``\n\n This migration is only safe to run before the code change is deployed.\n For example, a migration that adds a new field to a model.\n\n* ``Safe.after_deploy``\n\n This migration is only safe to run after the code change is deployed.\n This is the default that is applied if no ``safe`` property is given.\n For example, a migration that removes a field from a model.\n\n* ``Safe.always``\n\n This migration is safe to run before *and* after\n the code change is deployed.\n For example, a migration that changes the ``help_text`` of a field.\n\nPre-commit Hook\n===============\n\nTo get the most from django-safemigrate,\nit is important to make sure that all migrations\nare marked with the appropriate ``safe`` value.\nTo help with this, we provide a hook for use with ``pre-commit``.\n`Install and configure pre-commit`_,\nthen add this to the ``repos`` key of your ``.pre-commit-config.yaml``:\n\n.. code-block:: yaml\n\n repos:\n - repo: https://github.com/aspiredu/django-safemigrate\n rev: \"4.2\"\n hooks:\n - id: check\n\n.. _Install and configure pre-commit: https://pre-commit.com/\n\nNonstrict Mode\n==============\n\nUnder normal operation, if there are migrations\nthat must run before the deployment that depend\non any migration that is marked to run after deployment\n(or is not marked),\nthe command will raise an error to indicate\nthat there are protected migrations that\nshould have already been run, but have not been,\nand are blocking migrations that are expected to run.\n\nIn development, however, it is common that these\nwould accumulate between developers,\nand since it is acceptable for there to be downtime\nduring the transitional period in development,\nit is better to allow the command to continue without raising.\n\nTo enable nonstrict mode, add the ``SAFEMIGRATE`` setting:\n\n.. code-block:: python\n\n SAFEMIGRATE = \"nonstrict\"\n\nIn this mode ``safemigrate`` will run all the migrations\nthat are not blocked by any unsafe migrations.\nAny remaining migrations can be run after the fact\nusing the normal ``migrate`` Django command.\n\n\nContributing\n============\n\nTo get started contributing, you'll want to clone the repository,\ninstall dependencies via `poetry <https://python-poetry.org/>`_,\nand set up `pre-commit <https://pre-commit.com/>`_.\n\n.. code-block:: bash\n\n git clone git@github.com:aspiredu/django-safemigrate.git\n cd django-safemigrate\n poetry install\n pre-commit install\n\nTo run the tests use:\n\n.. code-block:: bash\n\n poetry run tox\n\nTo publish a new version:\n\n1. Find and replace all instances of the previous version with the new version.\n2. Commit and push that to origin.\n3. Tag the commit with the new version ``git tag 1.0`` and push that to origin.\n4. Create the\n `new release <https://github.com/aspiredu/django-safemigrate/releases/new>`_\n on GitHub.\n5. Publish the new version to PyPI with ``poetry publish``.\n\nSee `Poetry's docs\n<https://python-poetry.org/docs/repositories/#configuring-credentials>`_\non how to configure your local environment to publish to PyPI. Key your PyPI\ntoken to only django-safemigrate.\n\n.. code-block:: bash\n\n poetry config pypi-token.pypi <my-token>\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Safely run migrations before deployment",
"version": "4.2",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1e84c8b03322f9d85012ef2a7b99f3bd1d90942ef46d082a44b08b0d95988061",
"md5": "409ab688360f0f67a4288af045e78b1b",
"sha256": "a18f961f812d0c90ebd652a17cf80c68560461ca07e62a0ef8b4ff51bec62b29"
},
"downloads": -1,
"filename": "django_safemigrate-4.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "409ab688360f0f67a4288af045e78b1b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7411,
"upload_time": "2023-12-13T14:45:09",
"upload_time_iso_8601": "2023-12-13T14:45:09.623069Z",
"url": "https://files.pythonhosted.org/packages/1e/84/c8b03322f9d85012ef2a7b99f3bd1d90942ef46d082a44b08b0d95988061/django_safemigrate-4.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b586542534fe74f9aeb99716d63646f91c7965bcd5cc2772f4d2d27b59c4b829",
"md5": "b92ce834ba75cb03e9d8ff5adc6d41d1",
"sha256": "fd0ee8c258757fcc4b774b876cf587bd4df5f946ae6eb68643f05a5f88daaa20"
},
"downloads": -1,
"filename": "django_safemigrate-4.2.tar.gz",
"has_sig": false,
"md5_digest": "b92ce834ba75cb03e9d8ff5adc6d41d1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 5756,
"upload_time": "2023-12-13T14:45:11",
"upload_time_iso_8601": "2023-12-13T14:45:11.262270Z",
"url": "https://files.pythonhosted.org/packages/b5/86/542534fe74f9aeb99716d63646f91c7965bcd5cc2772f4d2d27b59c4b829/django_safemigrate-4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-13 14:45:11",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "django-safemigrate"
}