commands.makeworkflowmigrations
Overview
Management command for generating workflow state and transition migrations from change history.
Classes
compare_records
Return the fields whose value differs between two events.
Signature
compare_records(old_record, new_record)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| old_record | yes | ||
| new_record | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:854
get_history_diff
Classify one write and return what it changed.
A write with nothing before it is an add, and one whose event records a delete is a delete. Each compares against an empty row of the same model, so every field the write set or cleared shows up as a change.
Signature
get_history_diff(old_history_record, new_history_record)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| old_history_record | yes | ||
| new_history_record | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:864
get_migration_imports
Return the full, ordered set of import lines a workflow 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 updateworkflowmigrations 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_migration_imports(import_instead, direct_runpython_import, as_mapping)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| import_instead | yes | ||
| direct_runpython_import | yes | ||
| as_mapping | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:902
get_migration_sources
Return the source-code strings that follow changed_data in a workflow 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 updateworkflowmigrations to replace only the functions it recognizes in an existing migration, leaving any hand-added code around them untouched.
Signature
get_migration_sources(import_instead, as_mapping)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| import_instead | yes | ||
| as_mapping | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:960
manage_state_objects
Give every object of a workflow its initial state, and move one nothing has changed since.
An object state with only its creation recorded against it is still wherever it was put, so a changed initial state moves it. One that carries any later event was moved by someone, and the state they moved it to is theirs to keep.
TODO: An earlier run of this counts as someone, because its update is an event like any other. A workflow whose initial state changes twice therefore moves its objects only the first time. Telling the two apart needs the sync's own writes to be identifiable, which the action context cannot currently do here: pghistory sets its context as a transaction-local, so an action opened around these writes is still attributed to everything else written in the same transaction.
Signature
manage_state_objects(workflow, obj_class, workflow_obj_state_class, object_state_event_class, reversing)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| workflow | yes | ||
| obj_class | yes | ||
| workflow_obj_state_class | yes | ||
| object_state_event_class | yes | ||
| reversing | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:698
tracked_field_names
Return an event model's tracked columns as (name, attname) pairs.
pghistory copies the tracked row's concrete fields and adds its own pgh_ columns. Change data is keyed by field name and read by attname, so both are needed.
Signature
tracked_field_names(event_model)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| event_model | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:841
workflow_migration_action
Group every write a generated workflow migration makes under one action.
The events a migration writes are attributed to the system user and labelled with the migration that wrote them, so reading history back separates a migration's writes from a person's edit. Nothing else in the migration needs to know about it: the triggers record whatever the block writes, under whatever context is open.
The user model is read through the migration's own registry, because a migration must not depend on the shape the live model has now.
Signature
workflow_migration_action(apps, change_reason)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| apps | yes | ||
| change_reason | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:142
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py