commands.makegroupmigrations
Overview
Management command for generating group permission migrations from change history.
Classes
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(apps, changed_items)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| apps | yes | |||
| changed_items | yes |
Source
server/vueda/user/management/commands/makegroupmigrations.py:193
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(apps, schema_editor)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| apps | yes | |||
| schema_editor | yes |
Source
server/vueda/user/management/commands/makegroupmigrations.py:183
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(apps, changed_items)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| apps | yes | |||
| changed_items | yes |
Source
server/vueda/user/management/commands/makegroupmigrations.py:143
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(apps, schema_editor)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| apps | yes | |||
| schema_editor | yes |
Source
server/vueda/user/management/commands/makegroupmigrations.py:133
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(import_instead, direct_runpython_import, as_mapping)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| import_instead | no | False | ||
| direct_runpython_import | no | False | ||
| as_mapping | no | False |
Source
server/vueda/user/management/commands/makegroupmigrations.py:253
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(import_instead, as_mapping)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| import_instead | no | False | ||
| as_mapping | no | False |
Source
server/vueda/user/management/commands/makegroupmigrations.py:305
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(apps, schema_editor)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| apps | yes | |||
| schema_editor | yes |
Source
server/vueda/user/management/commands/makegroupmigrations.py:242
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(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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| content_types | yes | |||
| groups | yes | |||
| permissions | yes | |||
| group_name | yes | |||
| group_name_old | yes | |||
| change_type | yes | |||
| historical_permission_codename | yes | |||
| historical_permission_content_type_app_label | yes | |||
| historical_permission_content_type_model_name | yes | |||
| historical_permission_name | yes |
Source
server/vueda/user/management/commands/makegroupmigrations.py:71
Source
server/vueda/user/management/commands/makegroupmigrations.py