From 4efdbdc48ef4815f18d6e9062cba2b0863e39017 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 17 Apr 2023 15:42:58 -0400 Subject: [PATCH] try to make single process hash unique within full process model hash --- spiffworkflow-backend/migrations/env.py | 37 +- .../{0b5dd14bfbac_.py => 44a8f46cc508_.py} | 396 +++++++++++------- .../migrations/versions/5d8e49f9c560_.py | 36 -- .../models/bpmn_process_definition.py | 14 +- 4 files changed, 288 insertions(+), 195 deletions(-) rename spiffworkflow-backend/migrations/versions/{0b5dd14bfbac_.py => 44a8f46cc508_.py} (53%) delete mode 100644 spiffworkflow-backend/migrations/versions/5d8e49f9c560_.py diff --git a/spiffworkflow-backend/migrations/env.py b/spiffworkflow-backend/migrations/env.py index 630e381a..89f80b21 100644 --- a/spiffworkflow-backend/migrations/env.py +++ b/spiffworkflow-backend/migrations/env.py @@ -14,15 +14,30 @@ config = context.config fileConfig(config.config_file_name) logger = logging.getLogger('alembic.env') + +def get_engine(): + try: + # this works with Flask-SQLAlchemy<3 and Alchemical + return current_app.extensions['migrate'].db.get_engine() + except TypeError: + # this works with Flask-SQLAlchemy>=3 + return current_app.extensions['migrate'].db.engine + + +def get_engine_url(): + try: + return get_engine().url.render_as_string(hide_password=False).replace( + '%', '%%') + except AttributeError: + return str(get_engine().url).replace('%', '%%') + + # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata -config.set_main_option( - 'sqlalchemy.url', - str(current_app.extensions['migrate'].db.get_engine().url).replace( - '%', '%%')) -target_metadata = current_app.extensions['migrate'].db.metadata +config.set_main_option('sqlalchemy.url', get_engine_url()) +target_db = current_app.extensions['migrate'].db # other values from the config, defined by the needs of env.py, # can be acquired: @@ -30,6 +45,12 @@ target_metadata = current_app.extensions['migrate'].db.metadata # ... etc. +def get_metadata(): + if hasattr(target_db, 'metadatas'): + return target_db.metadatas[None] + return target_db.metadata + + def run_migrations_offline(): """Run migrations in 'offline' mode. @@ -44,7 +65,7 @@ def run_migrations_offline(): """ url = config.get_main_option("sqlalchemy.url") context.configure( - url=url, target_metadata=target_metadata, literal_binds=True + url=url, target_metadata=get_metadata(), literal_binds=True ) with context.begin_transaction(): @@ -69,12 +90,12 @@ def run_migrations_online(): directives[:] = [] logger.info('No changes in schema detected.') - connectable = current_app.extensions['migrate'].db.get_engine() + connectable = get_engine() with connectable.connect() as connection: context.configure( connection=connection, - target_metadata=target_metadata, + target_metadata=get_metadata(), process_revision_directives=process_revision_directives, **current_app.extensions['migrate'].configure_args ) diff --git a/spiffworkflow-backend/migrations/versions/0b5dd14bfbac_.py b/spiffworkflow-backend/migrations/versions/44a8f46cc508_.py similarity index 53% rename from spiffworkflow-backend/migrations/versions/0b5dd14bfbac_.py rename to spiffworkflow-backend/migrations/versions/44a8f46cc508_.py index d2ef7c10..da70af01 100644 --- a/spiffworkflow-backend/migrations/versions/0b5dd14bfbac_.py +++ b/spiffworkflow-backend/migrations/versions/44a8f46cc508_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: 0b5dd14bfbac +Revision ID: 44a8f46cc508 Revises: -Create Date: 2023-03-23 16:25:33.288500 +Create Date: 2023-04-17 15:40:28.658588 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa from sqlalchemy.dialects import mysql # revision identifiers, used by Alembic. -revision = '0b5dd14bfbac' +revision = '44a8f46cc508' down_revision = None branch_labels = None depends_on = None @@ -20,7 +20,8 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('bpmn_process_definition', sa.Column('id', sa.Integer(), nullable=False), - sa.Column('hash', sa.String(length=255), nullable=False), + sa.Column('single_process_hash', sa.String(length=255), nullable=False), + sa.Column('full_process_model_hash', sa.String(length=255), nullable=True), sa.Column('bpmn_identifier', sa.String(length=255), nullable=False), sa.Column('bpmn_name', sa.String(length=255), nullable=True), sa.Column('properties_json', sa.JSON(), nullable=False), @@ -29,10 +30,13 @@ def upgrade(): sa.Column('updated_at_in_seconds', sa.Integer(), nullable=True), sa.Column('created_at_in_seconds', sa.Integer(), nullable=True), sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('hash') + sa.UniqueConstraint('full_process_model_hash'), + sa.UniqueConstraint('full_process_model_hash', 'single_process_hash', name='process_hash_unique') ) - op.create_index(op.f('ix_bpmn_process_definition_bpmn_identifier'), 'bpmn_process_definition', ['bpmn_identifier'], unique=False) - op.create_index(op.f('ix_bpmn_process_definition_bpmn_name'), 'bpmn_process_definition', ['bpmn_name'], unique=False) + with op.batch_alter_table('bpmn_process_definition', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_bpmn_process_definition_bpmn_identifier'), ['bpmn_identifier'], unique=False) + batch_op.create_index(batch_op.f('ix_bpmn_process_definition_bpmn_name'), ['bpmn_name'], unique=False) + op.create_table('correlation_property_cache', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=50), nullable=False), @@ -41,16 +45,20 @@ def upgrade(): sa.Column('retrieval_expression', sa.String(length=255), nullable=True), sa.PrimaryKeyConstraint('id') ) - op.create_index(op.f('ix_correlation_property_cache_message_name'), 'correlation_property_cache', ['message_name'], unique=False) - op.create_index(op.f('ix_correlation_property_cache_name'), 'correlation_property_cache', ['name'], unique=False) + with op.batch_alter_table('correlation_property_cache', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_correlation_property_cache_message_name'), ['message_name'], unique=False) + batch_op.create_index(batch_op.f('ix_correlation_property_cache_name'), ['name'], unique=False) + op.create_table('group', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=255), nullable=True), sa.Column('identifier', sa.String(length=255), nullable=True), sa.PrimaryKeyConstraint('id') ) - op.create_index(op.f('ix_group_identifier'), 'group', ['identifier'], unique=False) - op.create_index(op.f('ix_group_name'), 'group', ['name'], unique=False) + with op.batch_alter_table('group', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_group_identifier'), ['identifier'], unique=False) + batch_op.create_index(batch_op.f('ix_group_name'), ['name'], unique=False) + op.create_table('json_data', sa.Column('id', sa.Integer(), nullable=False), sa.Column('hash', sa.String(length=255), nullable=False), @@ -66,8 +74,10 @@ def upgrade(): sa.Column('created_at_in_seconds', sa.Integer(), nullable=True), sa.PrimaryKeyConstraint('id') ) - op.create_index(op.f('ix_message_triggerable_process_model_message_name'), 'message_triggerable_process_model', ['message_name'], unique=False) - op.create_index(op.f('ix_message_triggerable_process_model_process_model_identifier'), 'message_triggerable_process_model', ['process_model_identifier'], unique=False) + with op.batch_alter_table('message_triggerable_process_model', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_message_triggerable_process_model_message_name'), ['message_name'], unique=False) + batch_op.create_index(batch_op.f('ix_message_triggerable_process_model_process_model_identifier'), ['process_model_identifier'], unique=False) + op.create_table('permission_target', sa.Column('id', sa.Integer(), nullable=False), sa.Column('uri', sa.String(length=255), nullable=False), @@ -88,10 +98,12 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('identifier', 'type', name='_identifier_type_unique') ) - op.create_index(op.f('ix_spec_reference_cache_display_name'), 'spec_reference_cache', ['display_name'], unique=False) - op.create_index(op.f('ix_spec_reference_cache_identifier'), 'spec_reference_cache', ['identifier'], unique=False) - op.create_index(op.f('ix_spec_reference_cache_process_model_id'), 'spec_reference_cache', ['process_model_id'], unique=False) - op.create_index(op.f('ix_spec_reference_cache_type'), 'spec_reference_cache', ['type'], unique=False) + with op.batch_alter_table('spec_reference_cache', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_spec_reference_cache_display_name'), ['display_name'], unique=False) + batch_op.create_index(batch_op.f('ix_spec_reference_cache_identifier'), ['identifier'], unique=False) + batch_op.create_index(batch_op.f('ix_spec_reference_cache_process_model_id'), ['process_model_id'], unique=False) + batch_op.create_index(batch_op.f('ix_spec_reference_cache_type'), ['type'], unique=False) + op.create_table('user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('username', sa.String(length=255), nullable=False), @@ -108,9 +120,11 @@ def upgrade(): sa.UniqueConstraint('service', 'service_id', name='service_key'), sa.UniqueConstraint('username') ) - op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=False) - op.create_index(op.f('ix_user_service'), 'user', ['service'], unique=False) - op.create_index(op.f('ix_user_service_id'), 'user', ['service_id'], unique=False) + with op.batch_alter_table('user', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_user_email'), ['email'], unique=False) + batch_op.create_index(batch_op.f('ix_user_service'), ['service'], unique=False) + batch_op.create_index(batch_op.f('ix_user_service_id'), ['service_id'], unique=False) + op.create_table('bpmn_process', sa.Column('id', sa.Integer(), nullable=False), sa.Column('guid', sa.String(length=36), nullable=True), @@ -127,10 +141,12 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('guid') ) - op.create_index(op.f('ix_bpmn_process_bpmn_process_definition_id'), 'bpmn_process', ['bpmn_process_definition_id'], unique=False) - op.create_index(op.f('ix_bpmn_process_direct_parent_process_id'), 'bpmn_process', ['direct_parent_process_id'], unique=False) - op.create_index(op.f('ix_bpmn_process_json_data_hash'), 'bpmn_process', ['json_data_hash'], unique=False) - op.create_index(op.f('ix_bpmn_process_top_level_process_id'), 'bpmn_process', ['top_level_process_id'], unique=False) + with op.batch_alter_table('bpmn_process', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_bpmn_process_bpmn_process_definition_id'), ['bpmn_process_definition_id'], unique=False) + batch_op.create_index(batch_op.f('ix_bpmn_process_direct_parent_process_id'), ['direct_parent_process_id'], unique=False) + batch_op.create_index(batch_op.f('ix_bpmn_process_json_data_hash'), ['json_data_hash'], unique=False) + batch_op.create_index(batch_op.f('ix_bpmn_process_top_level_process_id'), ['top_level_process_id'], unique=False) + op.create_table('bpmn_process_definition_relationship', sa.Column('id', sa.Integer(), nullable=False), sa.Column('bpmn_process_definition_parent_id', sa.Integer(), nullable=False), @@ -140,8 +156,10 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('bpmn_process_definition_parent_id', 'bpmn_process_definition_child_id', name='bpmn_process_definition_relationship_unique') ) - op.create_index(op.f('ix_bpmn_process_definition_relationship_bpmn_process_definition_parent_id'), 'bpmn_process_definition_relationship', ['bpmn_process_definition_parent_id'], unique=False) - op.create_index(op.f('ix_bpmn_process_definition_relationship_bpmn_process_definition_child_id'), 'bpmn_process_definition_relationship', ['bpmn_process_definition_child_id'], unique=False) + with op.batch_alter_table('bpmn_process_definition_relationship', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_bpmn_process_definition_relationship_bpmn_process_definition_parent_id'), ['bpmn_process_definition_parent_id'], unique=False) + batch_op.create_index(batch_op.f('ix_bpmn_process_definition_relationship_bpmn_process_definition_child_id'), ['bpmn_process_definition_child_id'], unique=False) + op.create_table('principal', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), @@ -164,8 +182,10 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('created_by_id', 'identifier', name='process_instance_report_unique') ) - op.create_index(op.f('ix_process_instance_report_created_by_id'), 'process_instance_report', ['created_by_id'], unique=False) - op.create_index(op.f('ix_process_instance_report_identifier'), 'process_instance_report', ['identifier'], unique=False) + with op.batch_alter_table('process_instance_report', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_process_instance_report_created_by_id'), ['created_by_id'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_report_identifier'), ['identifier'], unique=False) + op.create_table('refresh_token', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), @@ -185,7 +205,9 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('key') ) - op.create_index(op.f('ix_secret_user_id'), 'secret', ['user_id'], unique=False) + with op.batch_alter_table('secret', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_secret_user_id'), ['user_id'], unique=False) + op.create_table('task_definition', sa.Column('id', sa.Integer(), nullable=False), sa.Column('bpmn_process_definition_id', sa.Integer(), nullable=False), @@ -199,10 +221,12 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('bpmn_process_definition_id', 'bpmn_identifier', name='task_definition_unique') ) - op.create_index(op.f('ix_task_definition_bpmn_identifier'), 'task_definition', ['bpmn_identifier'], unique=False) - op.create_index(op.f('ix_task_definition_bpmn_name'), 'task_definition', ['bpmn_name'], unique=False) - op.create_index(op.f('ix_task_definition_bpmn_process_definition_id'), 'task_definition', ['bpmn_process_definition_id'], unique=False) - op.create_index(op.f('ix_task_definition_typename'), 'task_definition', ['typename'], unique=False) + with op.batch_alter_table('task_definition', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_task_definition_bpmn_identifier'), ['bpmn_identifier'], unique=False) + batch_op.create_index(batch_op.f('ix_task_definition_bpmn_name'), ['bpmn_name'], unique=False) + batch_op.create_index(batch_op.f('ix_task_definition_bpmn_process_definition_id'), ['bpmn_process_definition_id'], unique=False) + batch_op.create_index(batch_op.f('ix_task_definition_typename'), ['typename'], unique=False) + op.create_table('user_group_assignment', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), @@ -212,8 +236,10 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('user_id', 'group_id', name='user_group_assignment_unique') ) - op.create_index(op.f('ix_user_group_assignment_group_id'), 'user_group_assignment', ['group_id'], unique=False) - op.create_index(op.f('ix_user_group_assignment_user_id'), 'user_group_assignment', ['user_id'], unique=False) + with op.batch_alter_table('user_group_assignment', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_user_group_assignment_group_id'), ['group_id'], unique=False) + batch_op.create_index(batch_op.f('ix_user_group_assignment_user_id'), ['user_id'], unique=False) + op.create_table('user_group_assignment_waiting', sa.Column('id', sa.Integer(), nullable=False), sa.Column('username', sa.String(length=255), nullable=False), @@ -222,7 +248,9 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('username', 'group_id', name='user_group_assignment_staged_unique') ) - op.create_index(op.f('ix_user_group_assignment_waiting_group_id'), 'user_group_assignment_waiting', ['group_id'], unique=False) + with op.batch_alter_table('user_group_assignment_waiting', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_user_group_assignment_waiting_group_id'), ['group_id'], unique=False) + op.create_table('permission_assignment', sa.Column('id', sa.Integer(), nullable=False), sa.Column('principal_id', sa.Integer(), nullable=False), @@ -234,8 +262,10 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('principal_id', 'permission_target_id', 'permission', name='permission_assignment_uniq') ) - op.create_index(op.f('ix_permission_assignment_permission_target_id'), 'permission_assignment', ['permission_target_id'], unique=False) - op.create_index(op.f('ix_permission_assignment_principal_id'), 'permission_assignment', ['principal_id'], unique=False) + with op.batch_alter_table('permission_assignment', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_permission_assignment_permission_target_id'), ['permission_target_id'], unique=False) + batch_op.create_index(batch_op.f('ix_permission_assignment_principal_id'), ['principal_id'], unique=False) + op.create_table('process_instance', sa.Column('id', sa.Integer(), nullable=False), sa.Column('process_model_identifier', sa.String(length=255), nullable=False), @@ -256,14 +286,16 @@ def upgrade(): sa.ForeignKeyConstraint(['process_initiator_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_index(op.f('ix_process_instance_bpmn_process_definition_id'), 'process_instance', ['bpmn_process_definition_id'], unique=False) - op.create_index(op.f('ix_process_instance_bpmn_process_id'), 'process_instance', ['bpmn_process_id'], unique=False) - op.create_index(op.f('ix_process_instance_end_in_seconds'), 'process_instance', ['end_in_seconds'], unique=False) - op.create_index(op.f('ix_process_instance_process_initiator_id'), 'process_instance', ['process_initiator_id'], unique=False) - op.create_index(op.f('ix_process_instance_process_model_display_name'), 'process_instance', ['process_model_display_name'], unique=False) - op.create_index(op.f('ix_process_instance_process_model_identifier'), 'process_instance', ['process_model_identifier'], unique=False) - op.create_index(op.f('ix_process_instance_start_in_seconds'), 'process_instance', ['start_in_seconds'], unique=False) - op.create_index(op.f('ix_process_instance_status'), 'process_instance', ['status'], unique=False) + with op.batch_alter_table('process_instance', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_process_instance_bpmn_process_definition_id'), ['bpmn_process_definition_id'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_bpmn_process_id'), ['bpmn_process_id'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_end_in_seconds'), ['end_in_seconds'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_process_initiator_id'), ['process_initiator_id'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_process_model_display_name'), ['process_model_display_name'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_process_model_identifier'), ['process_model_identifier'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_start_in_seconds'), ['start_in_seconds'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_status'), ['status'], unique=False) + op.create_table('message_instance', sa.Column('id', sa.Integer(), nullable=False), sa.Column('process_instance_id', sa.Integer(), nullable=True), @@ -281,9 +313,11 @@ def upgrade(): sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_index(op.f('ix_message_instance_process_instance_id'), 'message_instance', ['process_instance_id'], unique=False) - op.create_index(op.f('ix_message_instance_status'), 'message_instance', ['status'], unique=False) - op.create_index(op.f('ix_message_instance_user_id'), 'message_instance', ['user_id'], unique=False) + with op.batch_alter_table('message_instance', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_message_instance_process_instance_id'), ['process_instance_id'], unique=False) + batch_op.create_index(batch_op.f('ix_message_instance_status'), ['status'], unique=False) + batch_op.create_index(batch_op.f('ix_message_instance_user_id'), ['user_id'], unique=False) + op.create_table('process_instance_event', sa.Column('id', sa.Integer(), nullable=False), sa.Column('task_guid', sa.String(length=36), nullable=True), @@ -295,11 +329,13 @@ def upgrade(): sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_index(op.f('ix_process_instance_event_event_type'), 'process_instance_event', ['event_type'], unique=False) - op.create_index(op.f('ix_process_instance_event_process_instance_id'), 'process_instance_event', ['process_instance_id'], unique=False) - op.create_index(op.f('ix_process_instance_event_task_guid'), 'process_instance_event', ['task_guid'], unique=False) - op.create_index(op.f('ix_process_instance_event_timestamp'), 'process_instance_event', ['timestamp'], unique=False) - op.create_index(op.f('ix_process_instance_event_user_id'), 'process_instance_event', ['user_id'], unique=False) + with op.batch_alter_table('process_instance_event', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_process_instance_event_event_type'), ['event_type'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_event_process_instance_id'), ['process_instance_id'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_event_task_guid'), ['task_guid'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_event_timestamp'), ['timestamp'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_event_user_id'), ['user_id'], unique=False) + op.create_table('process_instance_file_data', sa.Column('id', sa.Integer(), nullable=False), sa.Column('process_instance_id', sa.Integer(), nullable=False), @@ -314,8 +350,10 @@ def upgrade(): sa.ForeignKeyConstraint(['process_instance_id'], ['process_instance.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_index(op.f('ix_process_instance_file_data_digest'), 'process_instance_file_data', ['digest'], unique=False) - op.create_index(op.f('ix_process_instance_file_data_process_instance_id'), 'process_instance_file_data', ['process_instance_id'], unique=False) + with op.batch_alter_table('process_instance_file_data', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_process_instance_file_data_digest'), ['digest'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_file_data_process_instance_id'), ['process_instance_id'], unique=False) + op.create_table('process_instance_metadata', sa.Column('id', sa.Integer(), nullable=False), sa.Column('process_instance_id', sa.Integer(), nullable=False), @@ -327,8 +365,10 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('process_instance_id', 'key', name='process_instance_metadata_unique') ) - op.create_index(op.f('ix_process_instance_metadata_key'), 'process_instance_metadata', ['key'], unique=False) - op.create_index(op.f('ix_process_instance_metadata_process_instance_id'), 'process_instance_metadata', ['process_instance_id'], unique=False) + with op.batch_alter_table('process_instance_metadata', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_process_instance_metadata_key'), ['key'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_metadata_process_instance_id'), ['process_instance_id'], unique=False) + op.create_table('process_instance_queue', sa.Column('id', sa.Integer(), nullable=False), sa.Column('process_instance_id', sa.Integer(), nullable=False), @@ -343,9 +383,11 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('process_instance_id') ) - op.create_index(op.f('ix_process_instance_queue_locked_at_in_seconds'), 'process_instance_queue', ['locked_at_in_seconds'], unique=False) - op.create_index(op.f('ix_process_instance_queue_locked_by'), 'process_instance_queue', ['locked_by'], unique=False) - op.create_index(op.f('ix_process_instance_queue_status'), 'process_instance_queue', ['status'], unique=False) + with op.batch_alter_table('process_instance_queue', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_process_instance_queue_locked_at_in_seconds'), ['locked_at_in_seconds'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_queue_locked_by'), ['locked_by'], unique=False) + batch_op.create_index(batch_op.f('ix_process_instance_queue_status'), ['status'], unique=False) + op.create_table('task', sa.Column('id', sa.Integer(), nullable=False), sa.Column('guid', sa.String(length=36), nullable=False), @@ -364,12 +406,14 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('guid') ) - op.create_index(op.f('ix_task_bpmn_process_id'), 'task', ['bpmn_process_id'], unique=False) - op.create_index(op.f('ix_task_json_data_hash'), 'task', ['json_data_hash'], unique=False) - op.create_index(op.f('ix_task_process_instance_id'), 'task', ['process_instance_id'], unique=False) - op.create_index(op.f('ix_task_python_env_data_hash'), 'task', ['python_env_data_hash'], unique=False) - op.create_index(op.f('ix_task_state'), 'task', ['state'], unique=False) - op.create_index(op.f('ix_task_task_definition_id'), 'task', ['task_definition_id'], unique=False) + with op.batch_alter_table('task', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_task_bpmn_process_id'), ['bpmn_process_id'], unique=False) + batch_op.create_index(batch_op.f('ix_task_json_data_hash'), ['json_data_hash'], unique=False) + batch_op.create_index(batch_op.f('ix_task_process_instance_id'), ['process_instance_id'], unique=False) + batch_op.create_index(batch_op.f('ix_task_python_env_data_hash'), ['python_env_data_hash'], unique=False) + batch_op.create_index(batch_op.f('ix_task_state'), ['state'], unique=False) + batch_op.create_index(batch_op.f('ix_task_task_definition_id'), ['task_definition_id'], unique=False) + op.create_table('human_task', sa.Column('id', sa.Integer(), nullable=False), sa.Column('process_instance_id', sa.Integer(), nullable=False), @@ -396,12 +440,14 @@ def upgrade(): sa.ForeignKeyConstraint(['task_model_id'], ['task.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_index(op.f('ix_human_task_actual_owner_id'), 'human_task', ['actual_owner_id'], unique=False) - op.create_index(op.f('ix_human_task_completed'), 'human_task', ['completed'], unique=False) - op.create_index(op.f('ix_human_task_completed_by_user_id'), 'human_task', ['completed_by_user_id'], unique=False) - op.create_index(op.f('ix_human_task_lane_assignment_id'), 'human_task', ['lane_assignment_id'], unique=False) - op.create_index(op.f('ix_human_task_process_instance_id'), 'human_task', ['process_instance_id'], unique=False) - op.create_index(op.f('ix_human_task_task_model_id'), 'human_task', ['task_model_id'], unique=False) + with op.batch_alter_table('human_task', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_human_task_actual_owner_id'), ['actual_owner_id'], unique=False) + batch_op.create_index(batch_op.f('ix_human_task_completed'), ['completed'], unique=False) + batch_op.create_index(batch_op.f('ix_human_task_completed_by_user_id'), ['completed_by_user_id'], unique=False) + batch_op.create_index(batch_op.f('ix_human_task_lane_assignment_id'), ['lane_assignment_id'], unique=False) + batch_op.create_index(batch_op.f('ix_human_task_process_instance_id'), ['process_instance_id'], unique=False) + batch_op.create_index(batch_op.f('ix_human_task_task_model_id'), ['task_model_id'], unique=False) + op.create_table('message_instance_correlation_rule', sa.Column('id', sa.Integer(), nullable=False), sa.Column('message_instance_id', sa.Integer(), nullable=False), @@ -413,8 +459,10 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('message_instance_id', 'name', name='message_instance_id_name_unique') ) - op.create_index(op.f('ix_message_instance_correlation_rule_message_instance_id'), 'message_instance_correlation_rule', ['message_instance_id'], unique=False) - op.create_index(op.f('ix_message_instance_correlation_rule_name'), 'message_instance_correlation_rule', ['name'], unique=False) + with op.batch_alter_table('message_instance_correlation_rule', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_message_instance_correlation_rule_message_instance_id'), ['message_instance_id'], unique=False) + batch_op.create_index(batch_op.f('ix_message_instance_correlation_rule_name'), ['name'], unique=False) + op.create_table('human_task_user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('human_task_id', sa.Integer(), nullable=False), @@ -424,111 +472,161 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('human_task_id', 'user_id', name='human_task_user_unique') ) - op.create_index(op.f('ix_human_task_user_human_task_id'), 'human_task_user', ['human_task_id'], unique=False) - op.create_index(op.f('ix_human_task_user_user_id'), 'human_task_user', ['user_id'], unique=False) + with op.batch_alter_table('human_task_user', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_human_task_user_human_task_id'), ['human_task_id'], unique=False) + batch_op.create_index(batch_op.f('ix_human_task_user_user_id'), ['user_id'], unique=False) + # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_human_task_user_user_id'), table_name='human_task_user') - op.drop_index(op.f('ix_human_task_user_human_task_id'), table_name='human_task_user') + with op.batch_alter_table('human_task_user', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_human_task_user_user_id')) + batch_op.drop_index(batch_op.f('ix_human_task_user_human_task_id')) + op.drop_table('human_task_user') - op.drop_index(op.f('ix_message_instance_correlation_rule_name'), table_name='message_instance_correlation_rule') - op.drop_index(op.f('ix_message_instance_correlation_rule_message_instance_id'), table_name='message_instance_correlation_rule') + with op.batch_alter_table('message_instance_correlation_rule', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_message_instance_correlation_rule_name')) + batch_op.drop_index(batch_op.f('ix_message_instance_correlation_rule_message_instance_id')) + op.drop_table('message_instance_correlation_rule') - op.drop_index(op.f('ix_human_task_task_model_id'), table_name='human_task') - op.drop_index(op.f('ix_human_task_process_instance_id'), table_name='human_task') - op.drop_index(op.f('ix_human_task_lane_assignment_id'), table_name='human_task') - op.drop_index(op.f('ix_human_task_completed_by_user_id'), table_name='human_task') - op.drop_index(op.f('ix_human_task_completed'), table_name='human_task') - op.drop_index(op.f('ix_human_task_actual_owner_id'), table_name='human_task') + with op.batch_alter_table('human_task', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_human_task_task_model_id')) + batch_op.drop_index(batch_op.f('ix_human_task_process_instance_id')) + batch_op.drop_index(batch_op.f('ix_human_task_lane_assignment_id')) + batch_op.drop_index(batch_op.f('ix_human_task_completed_by_user_id')) + batch_op.drop_index(batch_op.f('ix_human_task_completed')) + batch_op.drop_index(batch_op.f('ix_human_task_actual_owner_id')) + op.drop_table('human_task') - op.drop_index(op.f('ix_task_task_definition_id'), table_name='task') - op.drop_index(op.f('ix_task_state'), table_name='task') - op.drop_index(op.f('ix_task_python_env_data_hash'), table_name='task') - op.drop_index(op.f('ix_task_process_instance_id'), table_name='task') - op.drop_index(op.f('ix_task_json_data_hash'), table_name='task') - op.drop_index(op.f('ix_task_bpmn_process_id'), table_name='task') + with op.batch_alter_table('task', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_task_task_definition_id')) + batch_op.drop_index(batch_op.f('ix_task_state')) + batch_op.drop_index(batch_op.f('ix_task_python_env_data_hash')) + batch_op.drop_index(batch_op.f('ix_task_process_instance_id')) + batch_op.drop_index(batch_op.f('ix_task_json_data_hash')) + batch_op.drop_index(batch_op.f('ix_task_bpmn_process_id')) + op.drop_table('task') - op.drop_index(op.f('ix_process_instance_queue_status'), table_name='process_instance_queue') - op.drop_index(op.f('ix_process_instance_queue_locked_by'), table_name='process_instance_queue') - op.drop_index(op.f('ix_process_instance_queue_locked_at_in_seconds'), table_name='process_instance_queue') + with op.batch_alter_table('process_instance_queue', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_process_instance_queue_status')) + batch_op.drop_index(batch_op.f('ix_process_instance_queue_locked_by')) + batch_op.drop_index(batch_op.f('ix_process_instance_queue_locked_at_in_seconds')) + op.drop_table('process_instance_queue') - op.drop_index(op.f('ix_process_instance_metadata_process_instance_id'), table_name='process_instance_metadata') - op.drop_index(op.f('ix_process_instance_metadata_key'), table_name='process_instance_metadata') + with op.batch_alter_table('process_instance_metadata', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_process_instance_metadata_process_instance_id')) + batch_op.drop_index(batch_op.f('ix_process_instance_metadata_key')) + op.drop_table('process_instance_metadata') - op.drop_index(op.f('ix_process_instance_file_data_process_instance_id'), table_name='process_instance_file_data') - op.drop_index(op.f('ix_process_instance_file_data_digest'), table_name='process_instance_file_data') + with op.batch_alter_table('process_instance_file_data', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_process_instance_file_data_process_instance_id')) + batch_op.drop_index(batch_op.f('ix_process_instance_file_data_digest')) + op.drop_table('process_instance_file_data') - op.drop_index(op.f('ix_process_instance_event_user_id'), table_name='process_instance_event') - op.drop_index(op.f('ix_process_instance_event_timestamp'), table_name='process_instance_event') - op.drop_index(op.f('ix_process_instance_event_task_guid'), table_name='process_instance_event') - op.drop_index(op.f('ix_process_instance_event_process_instance_id'), table_name='process_instance_event') - op.drop_index(op.f('ix_process_instance_event_event_type'), table_name='process_instance_event') + with op.batch_alter_table('process_instance_event', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_process_instance_event_user_id')) + batch_op.drop_index(batch_op.f('ix_process_instance_event_timestamp')) + batch_op.drop_index(batch_op.f('ix_process_instance_event_task_guid')) + batch_op.drop_index(batch_op.f('ix_process_instance_event_process_instance_id')) + batch_op.drop_index(batch_op.f('ix_process_instance_event_event_type')) + op.drop_table('process_instance_event') - op.drop_index(op.f('ix_message_instance_user_id'), table_name='message_instance') - op.drop_index(op.f('ix_message_instance_status'), table_name='message_instance') - op.drop_index(op.f('ix_message_instance_process_instance_id'), table_name='message_instance') + with op.batch_alter_table('message_instance', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_message_instance_user_id')) + batch_op.drop_index(batch_op.f('ix_message_instance_status')) + batch_op.drop_index(batch_op.f('ix_message_instance_process_instance_id')) + op.drop_table('message_instance') - op.drop_index(op.f('ix_process_instance_status'), table_name='process_instance') - op.drop_index(op.f('ix_process_instance_start_in_seconds'), table_name='process_instance') - op.drop_index(op.f('ix_process_instance_process_model_identifier'), table_name='process_instance') - op.drop_index(op.f('ix_process_instance_process_model_display_name'), table_name='process_instance') - op.drop_index(op.f('ix_process_instance_process_initiator_id'), table_name='process_instance') - op.drop_index(op.f('ix_process_instance_end_in_seconds'), table_name='process_instance') - op.drop_index(op.f('ix_process_instance_bpmn_process_id'), table_name='process_instance') - op.drop_index(op.f('ix_process_instance_bpmn_process_definition_id'), table_name='process_instance') + with op.batch_alter_table('process_instance', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_process_instance_status')) + batch_op.drop_index(batch_op.f('ix_process_instance_start_in_seconds')) + batch_op.drop_index(batch_op.f('ix_process_instance_process_model_identifier')) + batch_op.drop_index(batch_op.f('ix_process_instance_process_model_display_name')) + batch_op.drop_index(batch_op.f('ix_process_instance_process_initiator_id')) + batch_op.drop_index(batch_op.f('ix_process_instance_end_in_seconds')) + batch_op.drop_index(batch_op.f('ix_process_instance_bpmn_process_id')) + batch_op.drop_index(batch_op.f('ix_process_instance_bpmn_process_definition_id')) + op.drop_table('process_instance') - op.drop_index(op.f('ix_permission_assignment_principal_id'), table_name='permission_assignment') - op.drop_index(op.f('ix_permission_assignment_permission_target_id'), table_name='permission_assignment') + with op.batch_alter_table('permission_assignment', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_permission_assignment_principal_id')) + batch_op.drop_index(batch_op.f('ix_permission_assignment_permission_target_id')) + op.drop_table('permission_assignment') - op.drop_index(op.f('ix_user_group_assignment_waiting_group_id'), table_name='user_group_assignment_waiting') + with op.batch_alter_table('user_group_assignment_waiting', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_user_group_assignment_waiting_group_id')) + op.drop_table('user_group_assignment_waiting') - op.drop_index(op.f('ix_user_group_assignment_user_id'), table_name='user_group_assignment') - op.drop_index(op.f('ix_user_group_assignment_group_id'), table_name='user_group_assignment') + with op.batch_alter_table('user_group_assignment', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_user_group_assignment_user_id')) + batch_op.drop_index(batch_op.f('ix_user_group_assignment_group_id')) + op.drop_table('user_group_assignment') - op.drop_index(op.f('ix_task_definition_typename'), table_name='task_definition') - op.drop_index(op.f('ix_task_definition_bpmn_process_definition_id'), table_name='task_definition') - op.drop_index(op.f('ix_task_definition_bpmn_name'), table_name='task_definition') - op.drop_index(op.f('ix_task_definition_bpmn_identifier'), table_name='task_definition') + with op.batch_alter_table('task_definition', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_task_definition_typename')) + batch_op.drop_index(batch_op.f('ix_task_definition_bpmn_process_definition_id')) + batch_op.drop_index(batch_op.f('ix_task_definition_bpmn_name')) + batch_op.drop_index(batch_op.f('ix_task_definition_bpmn_identifier')) + op.drop_table('task_definition') - op.drop_index(op.f('ix_secret_user_id'), table_name='secret') + with op.batch_alter_table('secret', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_secret_user_id')) + op.drop_table('secret') op.drop_table('refresh_token') - op.drop_index(op.f('ix_process_instance_report_identifier'), table_name='process_instance_report') - op.drop_index(op.f('ix_process_instance_report_created_by_id'), table_name='process_instance_report') + with op.batch_alter_table('process_instance_report', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_process_instance_report_identifier')) + batch_op.drop_index(batch_op.f('ix_process_instance_report_created_by_id')) + op.drop_table('process_instance_report') op.drop_table('principal') - op.drop_index(op.f('ix_bpmn_process_definition_relationship_bpmn_process_definition_child_id'), table_name='bpmn_process_definition_relationship') - op.drop_index(op.f('ix_bpmn_process_definition_relationship_bpmn_process_definition_parent_id'), table_name='bpmn_process_definition_relationship') + with op.batch_alter_table('bpmn_process_definition_relationship', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_bpmn_process_definition_relationship_bpmn_process_definition_child_id')) + batch_op.drop_index(batch_op.f('ix_bpmn_process_definition_relationship_bpmn_process_definition_parent_id')) + op.drop_table('bpmn_process_definition_relationship') - op.drop_index(op.f('ix_bpmn_process_top_level_process_id'), table_name='bpmn_process') - op.drop_index(op.f('ix_bpmn_process_json_data_hash'), table_name='bpmn_process') - op.drop_index(op.f('ix_bpmn_process_direct_parent_process_id'), table_name='bpmn_process') - op.drop_index(op.f('ix_bpmn_process_bpmn_process_definition_id'), table_name='bpmn_process') + with op.batch_alter_table('bpmn_process', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_bpmn_process_top_level_process_id')) + batch_op.drop_index(batch_op.f('ix_bpmn_process_json_data_hash')) + batch_op.drop_index(batch_op.f('ix_bpmn_process_direct_parent_process_id')) + batch_op.drop_index(batch_op.f('ix_bpmn_process_bpmn_process_definition_id')) + op.drop_table('bpmn_process') - op.drop_index(op.f('ix_user_service_id'), table_name='user') - op.drop_index(op.f('ix_user_service'), table_name='user') - op.drop_index(op.f('ix_user_email'), table_name='user') + with op.batch_alter_table('user', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_user_service_id')) + batch_op.drop_index(batch_op.f('ix_user_service')) + batch_op.drop_index(batch_op.f('ix_user_email')) + op.drop_table('user') - op.drop_index(op.f('ix_spec_reference_cache_type'), table_name='spec_reference_cache') - op.drop_index(op.f('ix_spec_reference_cache_process_model_id'), table_name='spec_reference_cache') - op.drop_index(op.f('ix_spec_reference_cache_identifier'), table_name='spec_reference_cache') - op.drop_index(op.f('ix_spec_reference_cache_display_name'), table_name='spec_reference_cache') + with op.batch_alter_table('spec_reference_cache', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_spec_reference_cache_type')) + batch_op.drop_index(batch_op.f('ix_spec_reference_cache_process_model_id')) + batch_op.drop_index(batch_op.f('ix_spec_reference_cache_identifier')) + batch_op.drop_index(batch_op.f('ix_spec_reference_cache_display_name')) + op.drop_table('spec_reference_cache') op.drop_table('permission_target') - op.drop_index(op.f('ix_message_triggerable_process_model_process_model_identifier'), table_name='message_triggerable_process_model') - op.drop_index(op.f('ix_message_triggerable_process_model_message_name'), table_name='message_triggerable_process_model') + with op.batch_alter_table('message_triggerable_process_model', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_message_triggerable_process_model_process_model_identifier')) + batch_op.drop_index(batch_op.f('ix_message_triggerable_process_model_message_name')) + op.drop_table('message_triggerable_process_model') op.drop_table('json_data') - op.drop_index(op.f('ix_group_name'), table_name='group') - op.drop_index(op.f('ix_group_identifier'), table_name='group') + with op.batch_alter_table('group', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_group_name')) + batch_op.drop_index(batch_op.f('ix_group_identifier')) + op.drop_table('group') - op.drop_index(op.f('ix_correlation_property_cache_name'), table_name='correlation_property_cache') - op.drop_index(op.f('ix_correlation_property_cache_message_name'), table_name='correlation_property_cache') + with op.batch_alter_table('correlation_property_cache', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_correlation_property_cache_name')) + batch_op.drop_index(batch_op.f('ix_correlation_property_cache_message_name')) + op.drop_table('correlation_property_cache') - op.drop_index(op.f('ix_bpmn_process_definition_bpmn_name'), table_name='bpmn_process_definition') - op.drop_index(op.f('ix_bpmn_process_definition_bpmn_identifier'), table_name='bpmn_process_definition') + with op.batch_alter_table('bpmn_process_definition', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_bpmn_process_definition_bpmn_name')) + batch_op.drop_index(batch_op.f('ix_bpmn_process_definition_bpmn_identifier')) + op.drop_table('bpmn_process_definition') # ### end Alembic commands ### diff --git a/spiffworkflow-backend/migrations/versions/5d8e49f9c560_.py b/spiffworkflow-backend/migrations/versions/5d8e49f9c560_.py deleted file mode 100644 index 654c6a07..00000000 --- a/spiffworkflow-backend/migrations/versions/5d8e49f9c560_.py +++ /dev/null @@ -1,36 +0,0 @@ -"""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 ### diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/bpmn_process_definition.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/bpmn_process_definition.py index 615f529b..6aa37b9b 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/bpmn_process_definition.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/bpmn_process_definition.py @@ -2,6 +2,8 @@ from __future__ import annotations from dataclasses import dataclass +from sqlalchemy import UniqueConstraint + from spiffworkflow_backend.models.db import db from spiffworkflow_backend.models.db import SpiffworkflowBaseDBModel @@ -15,17 +17,25 @@ from spiffworkflow_backend.models.db import SpiffworkflowBaseDBModel @dataclass class BpmnProcessDefinitionModel(SpiffworkflowBaseDBModel): __tablename__ = "bpmn_process_definition" + __table_args__ = ( + UniqueConstraint( + "full_process_model_hash", + "single_process_hash", + name="process_hash_unique", + ), + ) + id: int = db.Column(db.Integer, primary_key=True) # this is a sha256 hash of spec and serializer_version # 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 # by multiple calling processes. - single_process_hash: str = db.Column(db.String(255), nullable=False, unique=True) + single_process_hash: str = db.Column(db.String(255), nullable=False) # 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) + full_process_model_hash: str | None = db.Column(db.String(255), nullable=True, unique=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)