django-migrate-or-rollback


Namedjango-migrate-or-rollback JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://github.com/zagaran/django-migrate-or-rollback
SummaryManagement command to attempt Django migrations and rollback on failure
upload_time2022-12-19 18:24:24
maintainer
docs_urlNone
authorZagaran, Inc.
requires_python>=3.6
licenseMIT
keywords django migrations
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-migrate-or-rollback

While single migrations in Django are atomic (as long as they have the default `atomic=True`),
a group of migrations are not.  Thus, when running migrations, you can have a partial
failure where some but not all of your migrations succeed.  This library fixes that.

This library provides a new management command `migrate_or_rollback`.  It's a drop-in
replacement for the Django builtin management command `migrate`.  Here's how it works:

1. Checks your database and current migration files for the latest migrations run per Django app.
2. Runs migrations as normal.
3. If migrations fail, it rolls back to the migrations identified in step 1.

## Instalation

`pip install django-migrate-or-rollback`

Alternatively, add `django-migrate-or-rollback` to your requirements.txt file.

Then, add `"django_migrate_or_rollback"` to your `INSTALLED_APPS` in settings.py, like so:

```
# settings.py
INSTALLED_APPS = [
    # ...
    "django_migrate_or_rollback",
]
```

## Usage

Run `python manage.py migrate_or_rollback` instead of the standard `migrate` command.

In particular, you should use `migrate_or_rollback` in place of `migrate` in your deployment scripts or CI/CD system.

`migrate_or_rollback` has all of the same options as `migrate`, such as the `--noinput` flag.


## Warning

This library assumes that your migrations are reversable.  Not all migrations are reversible.  Additionally, rolling back migrations only reverses schema doesn't rewind the database contents.

In particular:
* Deleted data (such as dropping columns or tables) won't be restored by rolling
back the migration that deletes it.  To avoid this, you should make fields
nullable in one deploy and delete them in the next.
* `RunPython` statements that are missing a `reverse` function will error on
rollback.  At a minimum, add `migrations.RunPython.noop` as a reverse function.
Additionally, RunPython reverse functions can be used to rewind changes to
database contents on migration rollback.
* A migration that deletes a non-nullable field will error on rollback.
To avoid this, make the field nullable in one deploy and delete it in the next.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zagaran/django-migrate-or-rollback",
    "name": "django-migrate-or-rollback",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "django migrations",
    "author": "Zagaran, Inc.",
    "author_email": "info@zagaran.com",
    "download_url": "https://files.pythonhosted.org/packages/1e/e7/da0d49e5f39d94e14561919557a4df42fe35e994d6768e912519db1b6ec1/django-migrate-or-rollback-0.0.2.tar.gz",
    "platform": null,
    "description": "# django-migrate-or-rollback\n\nWhile single migrations in Django are atomic (as long as they have the default `atomic=True`),\na group of migrations are not.  Thus, when running migrations, you can have a partial\nfailure where some but not all of your migrations succeed.  This library fixes that.\n\nThis library provides a new management command `migrate_or_rollback`.  It's a drop-in\nreplacement for the Django builtin management command `migrate`.  Here's how it works:\n\n1. Checks your database and current migration files for the latest migrations run per Django app.\n2. Runs migrations as normal.\n3. If migrations fail, it rolls back to the migrations identified in step 1.\n\n## Instalation\n\n`pip install django-migrate-or-rollback`\n\nAlternatively, add `django-migrate-or-rollback` to your requirements.txt file.\n\nThen, add `\"django_migrate_or_rollback\"` to your `INSTALLED_APPS` in settings.py, like so:\n\n```\n# settings.py\nINSTALLED_APPS = [\n    # ...\n    \"django_migrate_or_rollback\",\n]\n```\n\n## Usage\n\nRun `python manage.py migrate_or_rollback` instead of the standard `migrate` command.\n\nIn particular, you should use `migrate_or_rollback` in place of `migrate` in your deployment scripts or CI/CD system.\n\n`migrate_or_rollback` has all of the same options as `migrate`, such as the `--noinput` flag.\n\n\n## Warning\n\nThis library assumes that your migrations are reversable.  Not all migrations are reversible.  Additionally, rolling back migrations only reverses schema doesn't rewind the database contents.\n\nIn particular:\n* Deleted data (such as dropping columns or tables) won't be restored by rolling\nback the migration that deletes it.  To avoid this, you should make fields\nnullable in one deploy and delete them in the next.\n* `RunPython` statements that are missing a `reverse` function will error on\nrollback.  At a minimum, add `migrations.RunPython.noop` as a reverse function.\nAdditionally, RunPython reverse functions can be used to rewind changes to\ndatabase contents on migration rollback.\n* A migration that deletes a non-nullable field will error on rollback.\nTo avoid this, make the field nullable in one deploy and delete it in the next.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Management command to attempt Django migrations and rollback on failure",
    "version": "0.0.2",
    "split_keywords": [
        "django",
        "migrations"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "1bb0dbf54f8dfd14e08186fad03d7375",
                "sha256": "92c57877c5c32adc6124c342cd118e23c2fe483fe6416b287cb91ed583b9baf6"
            },
            "downloads": -1,
            "filename": "django_migrate_or_rollback-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1bb0dbf54f8dfd14e08186fad03d7375",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4527,
            "upload_time": "2022-12-19T18:24:23",
            "upload_time_iso_8601": "2022-12-19T18:24:23.448146Z",
            "url": "https://files.pythonhosted.org/packages/30/01/498c86c65022d7926b9cd494b84fcba7c87d7221c0dfe218ace903ebbba7/django_migrate_or_rollback-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "b782b0e519d922c607a817437e31861c",
                "sha256": "30c790743b076cf6493cd59f165fc7de21be417116c611ef8574ff4effa7b50f"
            },
            "downloads": -1,
            "filename": "django-migrate-or-rollback-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b782b0e519d922c607a817437e31861c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 3846,
            "upload_time": "2022-12-19T18:24:24",
            "upload_time_iso_8601": "2022-12-19T18:24:24.876233Z",
            "url": "https://files.pythonhosted.org/packages/1e/e7/da0d49e5f39d94e14561919557a4df42fe35e994d6768e912519db1b6ec1/django-migrate-or-rollback-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-19 18:24:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "zagaran",
    "github_project": "django-migrate-or-rollback",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-migrate-or-rollback"
}
        
Elapsed time: 0.02092s