vmigration-helper


Namevmigration-helper JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/bluedenim/vmigration-helper
SummaryVan's Django Migration Helper
upload_time2024-12-06 20:59:00
maintainerNone
docs_urlNone
authorbluedenim
requires_python<4.0,>=3.8
licenseNone
keywords django migration rollback
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Van's Migration Helper

Django commands to help with running Django migrations.

## Installation

* Add the dependency to your environment:

  ```
  pip install vmigration-helper
  ```

* Add the app `vmgration_helper.apps.VMigrationHelperConfig` to your list of installed apps in your settings:

  ```
  INSTALLED_APPS = [
    ...
    'vmigration_helper.apps.VMigrationHelperConfig',
    ...
  ]
  ```


## Commands

### migration_records

Shows existing migration records in your `django_migration` table.

```
> python manage.py migration_records
    ID Applied                           App Name
     1 2024-12-06T18:15:03+0000 contenttypes 0001_initial
     2 2024-12-06T18:15:03+0000         auth 0001_initial
     3 2024-12-06T18:15:03+0000        admin 0001_initial
     4 2024-12-06T18:15:03+0000        admin 0002_logentry_remove_auto_add
     5 2024-12-06T18:15:03+0000        admin 0003_logentry_add_action_flag_choices
     6 2024-12-06T18:15:03+0000 contenttypes 0002_remove_content_type_name
     7 2024-12-06T18:15:03+0000         auth 0002_alter_permission_name_max_length
     8 2024-12-06T18:15:03+0000         auth 0003_alter_user_email_max_length
     9 2024-12-06T18:15:03+0000         auth 0004_alter_user_username_opts
    10 2024-12-06T18:15:03+0000         auth 0005_alter_user_last_login_null
    11 2024-12-06T18:15:03+0000         auth 0006_require_contenttypes_0002
    12 2024-12-06T18:15:03+0000         auth 0007_alter_validators_add_error_messages
    13 2024-12-06T18:15:03+0000         auth 0008_alter_user_username_max_length
    14 2024-12-06T18:15:03+0000         auth 0009_alter_user_last_name_max_length
    15 2024-12-06T18:15:03+0000         auth 0010_alter_group_name_max_length
    16 2024-12-06T18:15:03+0000         auth 0011_update_proxy_permissions
    17 2024-12-06T18:15:03+0000         auth 0012_alter_user_first_name_max_length
    18 2024-12-06T18:15:03+0000     sessions 0001_initial

> python manage.py migration_records --format csv
ID,Applied,App,Name
1,2024-12-06T18:15:03+0000,contenttypes,0001_initial
2,2024-12-06T18:15:03+0000,auth,0001_initial
3,2024-12-06T18:15:03+0000,admin,0001_initial
4,2024-12-06T18:15:03+0000,admin,0002_logentry_remove_auto_add
5,2024-12-06T18:15:03+0000,admin,0003_logentry_add_action_flag_choices
6,2024-12-06T18:15:03+0000,contenttypes,0002_remove_content_type_name
7,2024-12-06T18:15:03+0000,auth,0002_alter_permission_name_max_length
8,2024-12-06T18:15:03+0000,auth,0003_alter_user_email_max_length
9,2024-12-06T18:15:03+0000,auth,0004_alter_user_username_opts
10,2024-12-06T18:15:03+0000,auth,0005_alter_user_last_login_null
11,2024-12-06T18:15:03+0000,auth,0006_require_contenttypes_0002
12,2024-12-06T18:15:03+0000,auth,0007_alter_validators_add_error_messages
13,2024-12-06T18:15:03+0000,auth,0008_alter_user_username_max_length
14,2024-12-06T18:15:03+0000,auth,0009_alter_user_last_name_max_length
15,2024-12-06T18:15:03+0000,auth,0010_alter_group_name_max_length
16,2024-12-06T18:15:03+0000,auth,0011_update_proxy_permissions
17,2024-12-06T18:15:03+0000,auth,0012_alter_user_first_name_max_length
18,2024-12-06T18:15:03+0000,sessions,0001_initial
```


These are the records of migrations applied. The fields indicate:
  * ID - the ID of the migration record
  * Applied - when the migration was applied 
  * App - name of the Django app
  * Name - name of the migration 

#### Optional parameters:

  * `--format (console | csv)` print the info in CSV or friendlier console format (default)
  * `--connection-name {connection}` the connection name to use (default is `django.db.DEFAULT_DB_ALIAS`)

### migration_current_id

Shows the ID of the latest migration record in your `django_migration` table.

```
> python manage.py migration_current_id
192
```

192 is the ID of the latest record as shown above.

#### Optional parameters:

  * `--connection-name {connection}` the connection name to use (default is `django.db.DEFAULT_DB_ALIAS`)

### migration_rollback

Roll-back (unapply) previously applied migrations _after_ (but not including) the migration ID provided.

```
> python manage.py migration_rollback 176
```

The above will rollback migrations after `0001_initial` of the `auth` app:

```
python manage.py migrate sessions zero
Operations to perform:
  Unapply all migrations: sessions
Running migrations:
  Rendering model states... DONE
  Unapplying sessions.0001_initial... OK

python manage.py migrate auth 0001_initial
Operations to perform:
  Target specific migration: 0001_initial, from auth
Running migrations:
  Rendering model states... DONE
  Unapplying auth.0012_alter_user_first_name_max_length... OK
  Unapplying auth.0011_update_proxy_permissions... OK
  Unapplying auth.0010_alter_group_name_max_length... OK
  Unapplying auth.0009_alter_user_last_name_max_length... OK
  Unapplying auth.0008_alter_user_username_max_length... OK
  Unapplying auth.0007_alter_validators_add_error_messages... OK
  Unapplying auth.0006_require_contenttypes_0002... OK
  Unapplying auth.0005_alter_user_last_login_null... OK
  Unapplying auth.0004_alter_user_username_opts... OK
  Unapplying auth.0003_alter_user_email_max_length... OK
  Unapplying auth.0002_alter_permission_name_max_length... OK

python manage.py migrate contenttypes 0001_initial
Operations to perform:
  Target specific migration: 0001_initial, from contenttypes
Running migrations:
  Rendering model states... DONE
  Unapplying contenttypes.0002_remove_content_type_name... OK

python manage.py migrate admin zero
Operations to perform:
  Unapply all migrations: admin
Running migrations:
  Rendering model states... DONE
  Unapplying admin.0003_logentry_add_action_flag_choices... OK
  Unapplying admin.0002_logentry_remove_auto_add... OK
  Unapplying admin.0001_initial... OK
```

#### Optional parameters:

  * `--connection-name {connection}` the connection name to use (default is `django.db.DEFAULT_DB_ALIAS`)
  * `--dry-run` will print the commands but will not actually run them
  * `--migrate-cmd <command to run migrations>` sets the command to run migrations with. The command must accept 
    the app and migration name as the `{app}` and `{name}` placeholders, respectively.  
    
    For example:
    
    ```
    --migrate-cmd "pipenv run python manage.py migrate {app} {name}" 
    ```
    
    can be used to have the command run migrations using `pipenv`.

    For example:

    ```
    > pipenv run python manage.py migration_rollback 0 --dry-run --migrate-cmd "pipenv run python manage.py migrate {app} {name}"
    pipenv run python manage.py migrate sessions zero
    pipenv run python manage.py migrate auth 0001_initial
    pipenv run python manage.py migrate contenttypes 0001_initial
    pipenv run python manage.py migrate admin zero
    pipenv run python manage.py migrate auth zero
    pipenv run python manage.py migrate contenttypes zero
    ```

### migration_delete

Deletes an entry from Django's migration records. This command should be
used only as a last resort to fix up migration records that cannot be rolled back. No migration up/down is performed; 
the record is simply removed from `django_migrations`.

NOTE also that migrations that depend on the record being deleted will be "broken" after the deletion, so this 
command should only be run on "leaf" migration records unless you plan to also delete other migration records that
depend on the one being deleted.

```
python manage.py migration_delete myapp 0003_some_migration
Confirm deletion of myapp:0003_some_migration (yes or no): yes
```
The command above deletes the migration `0003_some_migration` for the app `myapp` (after
getting confirmation).

To delete without confirmation, use the `--yes` option:
```
python manage.py migration_delete myapp 0003_some_migration --yes
```

#### Optional parameters:
  * `--connection-name {connection}` the connection name to use (default is `django.db.DEFAULT_DB_ALIAS`)
  * `--yes` will proceed to deleting the record without asking for confirmation


## Ideas for automation

Here's an idea for automating the deployment of your Django app using these utilities:

* Deploy new code
* Run `migration_current_id` and capture the current ID
* Run migration normally
* Run your automated tests normally
  * If tests pass, you're done!
  * If tests fail, and you need to rollback, run
  `migration_rollback <captured ID>`
  

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bluedenim/vmigration-helper",
    "name": "vmigration-helper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "django, migration, rollback",
    "author": "bluedenim",
    "author_email": "vancly@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2c/9d/0faab90ff72c938a6a6596b5abb8d78242f4513e50c1e646645dad90d1bf/vmigration_helper-1.1.0.tar.gz",
    "platform": null,
    "description": "# Van's Migration Helper\n\nDjango commands to help with running Django migrations.\n\n## Installation\n\n* Add the dependency to your environment:\n\n  ```\n  pip install vmigration-helper\n  ```\n\n* Add the app `vmgration_helper.apps.VMigrationHelperConfig` to your list of installed apps in your settings:\n\n  ```\n  INSTALLED_APPS = [\n    ...\n    'vmigration_helper.apps.VMigrationHelperConfig',\n    ...\n  ]\n  ```\n\n\n## Commands\n\n### migration_records\n\nShows existing migration records in your `django_migration` table.\n\n```\n> python manage.py migration_records\n    ID Applied                           App Name\n     1 2024-12-06T18:15:03+0000 contenttypes 0001_initial\n     2 2024-12-06T18:15:03+0000         auth 0001_initial\n     3 2024-12-06T18:15:03+0000        admin 0001_initial\n     4 2024-12-06T18:15:03+0000        admin 0002_logentry_remove_auto_add\n     5 2024-12-06T18:15:03+0000        admin 0003_logentry_add_action_flag_choices\n     6 2024-12-06T18:15:03+0000 contenttypes 0002_remove_content_type_name\n     7 2024-12-06T18:15:03+0000         auth 0002_alter_permission_name_max_length\n     8 2024-12-06T18:15:03+0000         auth 0003_alter_user_email_max_length\n     9 2024-12-06T18:15:03+0000         auth 0004_alter_user_username_opts\n    10 2024-12-06T18:15:03+0000         auth 0005_alter_user_last_login_null\n    11 2024-12-06T18:15:03+0000         auth 0006_require_contenttypes_0002\n    12 2024-12-06T18:15:03+0000         auth 0007_alter_validators_add_error_messages\n    13 2024-12-06T18:15:03+0000         auth 0008_alter_user_username_max_length\n    14 2024-12-06T18:15:03+0000         auth 0009_alter_user_last_name_max_length\n    15 2024-12-06T18:15:03+0000         auth 0010_alter_group_name_max_length\n    16 2024-12-06T18:15:03+0000         auth 0011_update_proxy_permissions\n    17 2024-12-06T18:15:03+0000         auth 0012_alter_user_first_name_max_length\n    18 2024-12-06T18:15:03+0000     sessions 0001_initial\n\n> python manage.py migration_records --format csv\nID,Applied,App,Name\n1,2024-12-06T18:15:03+0000,contenttypes,0001_initial\n2,2024-12-06T18:15:03+0000,auth,0001_initial\n3,2024-12-06T18:15:03+0000,admin,0001_initial\n4,2024-12-06T18:15:03+0000,admin,0002_logentry_remove_auto_add\n5,2024-12-06T18:15:03+0000,admin,0003_logentry_add_action_flag_choices\n6,2024-12-06T18:15:03+0000,contenttypes,0002_remove_content_type_name\n7,2024-12-06T18:15:03+0000,auth,0002_alter_permission_name_max_length\n8,2024-12-06T18:15:03+0000,auth,0003_alter_user_email_max_length\n9,2024-12-06T18:15:03+0000,auth,0004_alter_user_username_opts\n10,2024-12-06T18:15:03+0000,auth,0005_alter_user_last_login_null\n11,2024-12-06T18:15:03+0000,auth,0006_require_contenttypes_0002\n12,2024-12-06T18:15:03+0000,auth,0007_alter_validators_add_error_messages\n13,2024-12-06T18:15:03+0000,auth,0008_alter_user_username_max_length\n14,2024-12-06T18:15:03+0000,auth,0009_alter_user_last_name_max_length\n15,2024-12-06T18:15:03+0000,auth,0010_alter_group_name_max_length\n16,2024-12-06T18:15:03+0000,auth,0011_update_proxy_permissions\n17,2024-12-06T18:15:03+0000,auth,0012_alter_user_first_name_max_length\n18,2024-12-06T18:15:03+0000,sessions,0001_initial\n```\n\n\nThese are the records of migrations applied. The fields indicate:\n  * ID - the ID of the migration record\n  * Applied - when the migration was applied \n  * App - name of the Django app\n  * Name - name of the migration \n\n#### Optional parameters:\n\n  * `--format (console | csv)` print the info in CSV or friendlier console format (default)\n  * `--connection-name {connection}` the connection name to use (default is `django.db.DEFAULT_DB_ALIAS`)\n\n### migration_current_id\n\nShows the ID of the latest migration record in your `django_migration` table.\n\n```\n> python manage.py migration_current_id\n192\n```\n\n192 is the ID of the latest record as shown above.\n\n#### Optional parameters:\n\n  * `--connection-name {connection}` the connection name to use (default is `django.db.DEFAULT_DB_ALIAS`)\n\n### migration_rollback\n\nRoll-back (unapply) previously applied migrations _after_ (but not including) the migration ID provided.\n\n```\n> python manage.py migration_rollback 176\n```\n\nThe above will rollback migrations after `0001_initial` of the `auth` app:\n\n```\npython manage.py migrate sessions zero\nOperations to perform:\n  Unapply all migrations: sessions\nRunning migrations:\n  Rendering model states... DONE\n  Unapplying sessions.0001_initial... OK\n\npython manage.py migrate auth 0001_initial\nOperations to perform:\n  Target specific migration: 0001_initial, from auth\nRunning migrations:\n  Rendering model states... DONE\n  Unapplying auth.0012_alter_user_first_name_max_length... OK\n  Unapplying auth.0011_update_proxy_permissions... OK\n  Unapplying auth.0010_alter_group_name_max_length... OK\n  Unapplying auth.0009_alter_user_last_name_max_length... OK\n  Unapplying auth.0008_alter_user_username_max_length... OK\n  Unapplying auth.0007_alter_validators_add_error_messages... OK\n  Unapplying auth.0006_require_contenttypes_0002... OK\n  Unapplying auth.0005_alter_user_last_login_null... OK\n  Unapplying auth.0004_alter_user_username_opts... OK\n  Unapplying auth.0003_alter_user_email_max_length... OK\n  Unapplying auth.0002_alter_permission_name_max_length... OK\n\npython manage.py migrate contenttypes 0001_initial\nOperations to perform:\n  Target specific migration: 0001_initial, from contenttypes\nRunning migrations:\n  Rendering model states... DONE\n  Unapplying contenttypes.0002_remove_content_type_name... OK\n\npython manage.py migrate admin zero\nOperations to perform:\n  Unapply all migrations: admin\nRunning migrations:\n  Rendering model states... DONE\n  Unapplying admin.0003_logentry_add_action_flag_choices... OK\n  Unapplying admin.0002_logentry_remove_auto_add... OK\n  Unapplying admin.0001_initial... OK\n```\n\n#### Optional parameters:\n\n  * `--connection-name {connection}` the connection name to use (default is `django.db.DEFAULT_DB_ALIAS`)\n  * `--dry-run` will print the commands but will not actually run them\n  * `--migrate-cmd <command to run migrations>` sets the command to run migrations with. The command must accept \n    the app and migration name as the `{app}` and `{name}` placeholders, respectively.  \n    \n    For example:\n    \n    ```\n    --migrate-cmd \"pipenv run python manage.py migrate {app} {name}\" \n    ```\n    \n    can be used to have the command run migrations using `pipenv`.\n\n    For example:\n\n    ```\n    > pipenv run python manage.py migration_rollback 0 --dry-run --migrate-cmd \"pipenv run python manage.py migrate {app} {name}\"\n    pipenv run python manage.py migrate sessions zero\n    pipenv run python manage.py migrate auth 0001_initial\n    pipenv run python manage.py migrate contenttypes 0001_initial\n    pipenv run python manage.py migrate admin zero\n    pipenv run python manage.py migrate auth zero\n    pipenv run python manage.py migrate contenttypes zero\n    ```\n\n### migration_delete\n\nDeletes an entry from Django's migration records. This command should be\nused only as a last resort to fix up migration records that cannot be rolled back. No migration up/down is performed; \nthe record is simply removed from `django_migrations`.\n\nNOTE also that migrations that depend on the record being deleted will be \"broken\" after the deletion, so this \ncommand should only be run on \"leaf\" migration records unless you plan to also delete other migration records that\ndepend on the one being deleted.\n\n```\npython manage.py migration_delete myapp 0003_some_migration\nConfirm deletion of myapp:0003_some_migration (yes or no): yes\n```\nThe command above deletes the migration `0003_some_migration` for the app `myapp` (after\ngetting confirmation).\n\nTo delete without confirmation, use the `--yes` option:\n```\npython manage.py migration_delete myapp 0003_some_migration --yes\n```\n\n#### Optional parameters:\n  * `--connection-name {connection}` the connection name to use (default is `django.db.DEFAULT_DB_ALIAS`)\n  * `--yes` will proceed to deleting the record without asking for confirmation\n\n\n## Ideas for automation\n\nHere's an idea for automating the deployment of your Django app using these utilities:\n\n* Deploy new code\n* Run `migration_current_id` and capture the current ID\n* Run migration normally\n* Run your automated tests normally\n  * If tests pass, you're done!\n  * If tests fail, and you need to rollback, run\n  `migration_rollback <captured ID>`\n  \n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Van's Django Migration Helper",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/bluedenim/vmigration-helper"
    },
    "split_keywords": [
        "django",
        " migration",
        " rollback"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e7457ddfd5cdef9967e53f9339a67987470caee994c8d13ec4d0a055814a507b",
                "md5": "c55032477c7e89b35ce26158d3ad254d",
                "sha256": "f0790ccdb63a41cf860f381d94c6f92b49fc4b0cc49a25d5e35028e80fc3c9fd"
            },
            "downloads": -1,
            "filename": "vmigration_helper-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c55032477c7e89b35ce26158d3ad254d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 11427,
            "upload_time": "2024-12-06T20:58:59",
            "upload_time_iso_8601": "2024-12-06T20:58:59.154104Z",
            "url": "https://files.pythonhosted.org/packages/e7/45/7ddfd5cdef9967e53f9339a67987470caee994c8d13ec4d0a055814a507b/vmigration_helper-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2c9d0faab90ff72c938a6a6596b5abb8d78242f4513e50c1e646645dad90d1bf",
                "md5": "4cd16c430368d69b7fedc47b34e622b8",
                "sha256": "aa9eb077401dd0245c6e1b1d0655a8fbe5a7a77b037c7fe7c3eddc4c52446393"
            },
            "downloads": -1,
            "filename": "vmigration_helper-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4cd16c430368d69b7fedc47b34e622b8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 9481,
            "upload_time": "2024-12-06T20:59:00",
            "upload_time_iso_8601": "2024-12-06T20:59:00.632696Z",
            "url": "https://files.pythonhosted.org/packages/2c/9d/0faab90ff72c938a6a6596b5abb8d78242f4513e50c1e646645dad90d1bf/vmigration_helper-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-06 20:59:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bluedenim",
    "github_project": "vmigration-helper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "vmigration-helper"
}
        
Elapsed time: 0.62926s