Skip to content

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

NameTypeRequiredDescription
old_recordyes
new_recordyes

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

NameTypeRequiredDescription
old_history_recordyes
new_history_recordyes

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

NameTypeRequiredDescription
import_insteadyes
direct_runpython_importyes
as_mappingyes

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

NameTypeRequiredDescription
import_insteadyes
as_mappingyes

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

NameTypeRequiredDescription
workflowyes
obj_classyes
workflow_obj_state_classyes
object_state_event_classyes
reversingyes

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

NameTypeRequiredDescription
event_modelyes

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

NameTypeRequiredDescription
appsyes
change_reasonyes

Source

server/vueda/workflow/management/commands/makeworkflowmigrations.py:142

Source

server/vueda/workflow/management/commands/makeworkflowmigrations.py

Documents matching: server v3.0.0a1.post1client v3.0.0-alpha.2