---
url: "https://vueda.dev/v3/reference/api/py/vueda.user.management.commands.makegroupmigrations.md"
title: "commands.makegroupmigrations"
---

# commands.makegroupmigrations

## Overview

Management command for generating group permission migrations from change history.

## Classes

- [Command](/v3/reference/api/py/vueda.user.management.commands.makegroupmigrations/Command.md)
- [GroupChangeTypes](/v3/reference/api/py/vueda.user.management.commands.makegroupmigrations/GroupChangeTypes.md)

## `backwards_migrate_groups` {#backwards_migrate_groups}

Undo each change in ``changed_items`` in reverse order by applying its opposite change.

It does not remove the ``GroupChange`` rows that ``forwards_migrate_groups`` recorded. Generated group
migrations copy this function into their source, or import it when made with ``--import-instead``.

### Signature {#backwards_migrate_groups-signature}

`backwards_migrate_groups(apps, changed_items)`

#### Parameters {#backwards_migrate_groups-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <span id="backwards_migrate_groups-param-apps">apps</span> |  | yes |  |  |
| <span id="backwards_migrate_groups-param-changed_items">changed_items</span> |  | yes |  |  |

### Source {#backwards_migrate_groups-source}

`server/vueda/user/management/commands/makegroupmigrations.py:193`

## `backwards_migrate_groups_through_imports` {#backwards_migrate_groups_through_imports}

Reverse a copy of the migration module's ``changed_data`` through ``backwards_migrate_groups``.

Every generated group migration copies this function into its source and runs it as its reverse ``RunPython``
operation.

### Signature {#backwards_migrate_groups_through_imports-signature}

`backwards_migrate_groups_through_imports(apps, schema_editor)`

#### Parameters {#backwards_migrate_groups_through_imports-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <span id="backwards_migrate_groups_through_imports-param-apps">apps</span> |  | yes |  |  |
| <span id="backwards_migrate_groups_through_imports-param-schema_editor">schema_editor</span> |  | yes |  |  |

### Source {#backwards_migrate_groups_through_imports-source}

`server/vueda/user/management/commands/makegroupmigrations.py:183`

## `forwards_migrate_groups` {#forwards_migrate_groups}

Apply each change in ``changed_items`` in order, and record a ``GroupChange`` row for any change not already
stored.

Generated group migrations copy this function into their source, or import it when made with
``--import-instead``.

### Signature {#forwards_migrate_groups-signature}

`forwards_migrate_groups(apps, changed_items)`

#### Parameters {#forwards_migrate_groups-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <span id="forwards_migrate_groups-param-apps">apps</span> |  | yes |  |  |
| <span id="forwards_migrate_groups-param-changed_items">changed_items</span> |  | yes |  |  |

### Source {#forwards_migrate_groups-source}

`server/vueda/user/management/commands/makegroupmigrations.py:143`

## `forwards_migrate_groups_through_imports` {#forwards_migrate_groups_through_imports}

Apply a copy of the migration module's ``changed_data`` through ``forwards_migrate_groups``.

Every generated group migration copies this function into its source and runs it as its forward ``RunPython``
operation.

### Signature {#forwards_migrate_groups_through_imports-signature}

`forwards_migrate_groups_through_imports(apps, schema_editor)`

#### Parameters {#forwards_migrate_groups_through_imports-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <span id="forwards_migrate_groups_through_imports-param-apps">apps</span> |  | yes |  |  |
| <span id="forwards_migrate_groups_through_imports-param-schema_editor">schema_editor</span> |  | yes |  |  |

### Source {#forwards_migrate_groups_through_imports-source}

`server/vueda/user/management/commands/makegroupmigrations.py:133`

## `get_group_migration_imports` {#get_group_migration_imports}

Return the full, ordered set of import lines a group migration file's import section is replaced with.

``direct_runpython_import`` adds a direct ``from django.db.migrations import RunPython`` import, needed
when the class Migration block being preserved calls ``RunPython(...)`` directly instead of
``migrations.RunPython(...)``.

When ``as_mapping`` is True, an ordered mapping is returned instead: keys are single-name tuples (an
import only ever binds one name, per this project's force-single-line isort convention) and values are
the current import line, each ending in its own newline and prefixed with a blank line where it opens
a new isort group. This is used by ``updategroupmigrations`` to update or insert only the imports it
recognizes in an existing migration, leaving any hand-added imports (or comments) around them
untouched.

### Signature {#get_group_migration_imports-signature}

`get_group_migration_imports(import_instead, direct_runpython_import, as_mapping)`

#### Parameters {#get_group_migration_imports-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <span id="get_group_migration_imports-param-import_instead">import_instead</span> |  | no | `False` |  |
| <span id="get_group_migration_imports-param-direct_runpython_import">direct_runpython_import</span> |  | no | `False` |  |
| <span id="get_group_migration_imports-param-as_mapping">as_mapping</span> |  | no | `False` |  |

### Source {#get_group_migration_imports-source}

`server/vueda/user/management/commands/makegroupmigrations.py:253`

## `get_group_migration_sources` {#get_group_migration_sources}

Return the source-code strings inserted into a group migration file.

When ``as_mapping`` is True, an ordered mapping is returned instead: keys are tuples of every name
(old and current) that identifies a given function/class across versions of this command, and values
are the current source for it. This is used by ``updategroupmigrations`` to replace only the functions
it recognizes in an existing migration, leaving any hand-added code around them untouched.

### Signature {#get_group_migration_sources-signature}

`get_group_migration_sources(import_instead, as_mapping)`

#### Parameters {#get_group_migration_sources-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <span id="get_group_migration_sources-param-import_instead">import_instead</span> |  | no | `False` |  |
| <span id="get_group_migration_sources-param-as_mapping">as_mapping</span> |  | no | `False` |  |

### Source {#get_group_migration_sources-source}

`server/vueda/user/management/commands/makegroupmigrations.py:305`

## `make_sure_permissions_exist` {#make_sure_permissions_exist}

Create any missing permissions for every installed app, so later group steps can find them.

Generated group migrations run this as their first ``RunPython`` operation. They copy it into their source, or
import it when made with ``--import-instead``.

### Signature {#make_sure_permissions_exist-signature}

`make_sure_permissions_exist(apps, schema_editor)`

#### Parameters {#make_sure_permissions_exist-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <span id="make_sure_permissions_exist-param-apps">apps</span> |  | yes |  |  |
| <span id="make_sure_permissions_exist-param-schema_editor">schema_editor</span> |  | yes |  |  |

### Source {#make_sure_permissions_exist-source}

`server/vueda/user/management/commands/makegroupmigrations.py:242`

## `migrate_step` {#migrate_step}

Apply one recorded group change to the database, using the historical ``groups``, ``permissions``, and
``content_types`` models passed in.

Add, associate, and change steps create or rename the group and grant it the permission; unassociate and
delete steps revoke it. Generated group migrations copy this function into their own source.

### Signature {#migrate_step-signature}

`migrate_step(content_types, groups, permissions, group_name, group_name_old, change_type, historical_permission_codename, historical_permission_content_type_app_label, historical_permission_content_type_model_name, historical_permission_name)`

#### Parameters {#migrate_step-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <span id="migrate_step-param-content_types">content_types</span> |  | yes |  |  |
| <span id="migrate_step-param-groups">groups</span> |  | yes |  |  |
| <span id="migrate_step-param-permissions">permissions</span> |  | yes |  |  |
| <span id="migrate_step-param-group_name">group_name</span> |  | yes |  |  |
| <span id="migrate_step-param-group_name_old">group_name_old</span> |  | yes |  |  |
| <span id="migrate_step-param-change_type">change_type</span> |  | yes |  |  |
| <span id="migrate_step-param-historical_permission_codename">historical_permission_codename</span> |  | yes |  |  |
| <span id="migrate_step-param-historical_permission_content_type_app_label">historical_permission_content_type_app_label</span> |  | yes |  |  |
| <span id="migrate_step-param-historical_permission_content_type_model_name">historical_permission_content_type_model_name</span> |  | yes |  |  |
| <span id="migrate_step-param-historical_permission_name">historical_permission_name</span> |  | yes |  |  |

### Source {#migrate_step-source}

`server/vueda/user/management/commands/makegroupmigrations.py:71`

## Source

`server/vueda/user/management/commands/makegroupmigrations.py`
