added new column to bpmn process definition to store the full bpmn process hash digest w/ burnettk

This commit is contained in:
jasquat 2023-04-17 12:01:36 -04:00
parent 3e0af7ac3f
commit 3c8aab1048
No known key found for this signature in database
3 changed files with 60 additions and 6 deletions

View File

@ -0,0 +1,36 @@
"""empty message
Revision ID: 5d8e49f9c560
Revises: 0b5dd14bfbac
Create Date: 2023-04-17 11:28:39.714193
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '5d8e49f9c560'
down_revision = '0b5dd14bfbac'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('bpmn_process_definition', schema=None) as batch_op:
batch_op.alter_column('hash', existing_type=sa.String(length=255), new_column_name='single_process_hash')
batch_op.add_column(sa.Column('full_process_model_hash', sa.String(length=255), nullable=True))
batch_op.create_unique_constraint(None, ['full_process_model_hash'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('bpmn_process_definition', schema=None) as batch_op:
batch_op.drop_constraint('full_process_model_hash', type_='unique')
batch_op.drop_column('full_process_model_hash')
batch_op.alter_column('single_process_hash', existing_type=sa.String(length=255), new_column_name='hash')
# ### end Alembic commands ###

View File

@ -21,7 +21,11 @@ class BpmnProcessDefinitionModel(SpiffworkflowBaseDBModel):
# note that a call activity is its own row in this table, with its own hash, # note that a call activity is its own row in this table, with its own hash,
# and therefore it only gets stored once per version, and can be reused # and therefore it only gets stored once per version, and can be reused
# by multiple calling processes. # by multiple calling processes.
hash: str = db.Column(db.String(255), nullable=False, unique=True) single_process_hash: str = db.Column(db.String(255), nullable=False, unique=True)
# only the top level parent will have this set
# it includes all subprocesses and call activities
full_process_model_hash: str | None = db.Column(db.String(255), nullable=True, unique=True, default=None)
bpmn_identifier: str = db.Column(db.String(255), nullable=False, index=True) bpmn_identifier: str = db.Column(db.String(255), nullable=False, index=True)
bpmn_name: str = db.Column(db.String(255), nullable=True, index=True) bpmn_name: str = db.Column(db.String(255), nullable=True, index=True)

View File

@ -959,18 +959,31 @@ class ProcessInstanceProcessor:
process_bpmn_properties: dict, process_bpmn_properties: dict,
bpmn_process_definition_parent: Optional[BpmnProcessDefinitionModel] = None, bpmn_process_definition_parent: Optional[BpmnProcessDefinitionModel] = None,
store_bpmn_definition_mappings: bool = False, store_bpmn_definition_mappings: bool = False,
full_bpmn_spec_dict: Optional[dict] = None,
) -> BpmnProcessDefinitionModel: ) -> BpmnProcessDefinitionModel:
process_bpmn_identifier = process_bpmn_properties["name"] process_bpmn_identifier = process_bpmn_properties["name"]
process_bpmn_name = process_bpmn_properties["description"] process_bpmn_name = process_bpmn_properties["description"]
new_hash_digest = sha256(json.dumps(process_bpmn_properties, sort_keys=True).encode("utf8")).hexdigest()
bpmn_process_definition: Optional[BpmnProcessDefinitionModel] = BpmnProcessDefinitionModel.query.filter_by( bpmn_process_definition: Optional[BpmnProcessDefinitionModel] = None
hash=new_hash_digest single_process_hash = sha256(json.dumps(process_bpmn_properties, sort_keys=True).encode("utf8")).hexdigest()
full_process_model_hash = None
if full_bpmn_spec_dict is not None:
full_process_model_hash = sha256(
json.dumps(full_bpmn_spec_dict, sort_keys=True).encode("utf8")
).hexdigest()
bpmn_process_definition = BpmnProcessDefinitionModel.query.filter_by(
full_process_model_hash=full_process_model_hash
).first()
else:
bpmn_process_definition = BpmnProcessDefinitionModel.query.filter_by(
single_process_hash=single_process_hash
).first() ).first()
if bpmn_process_definition is None: if bpmn_process_definition is None:
task_specs = process_bpmn_properties.pop("task_specs") task_specs = process_bpmn_properties.pop("task_specs")
bpmn_process_definition = BpmnProcessDefinitionModel( bpmn_process_definition = BpmnProcessDefinitionModel(
hash=new_hash_digest, single_process_hash=single_process_hash,
full_process_model_hash=full_process_model_hash,
bpmn_identifier=process_bpmn_identifier, bpmn_identifier=process_bpmn_identifier,
bpmn_name=process_bpmn_name, bpmn_name=process_bpmn_name,
properties_json=process_bpmn_properties, properties_json=process_bpmn_properties,
@ -1050,6 +1063,7 @@ class ProcessInstanceProcessor:
bpmn_process_definition_parent = self._store_bpmn_process_definition( bpmn_process_definition_parent = self._store_bpmn_process_definition(
bpmn_spec_dict["spec"], bpmn_spec_dict["spec"],
store_bpmn_definition_mappings=store_bpmn_definition_mappings, store_bpmn_definition_mappings=store_bpmn_definition_mappings,
full_bpmn_spec_dict=bpmn_spec_dict,
) )
for process_bpmn_properties in bpmn_spec_dict["subprocess_specs"].values(): for process_bpmn_properties in bpmn_spec_dict["subprocess_specs"].values():
self._store_bpmn_process_definition( self._store_bpmn_process_definition(