From 9b199cad711959fc59b1d88f618af17b2e4cf578 Mon Sep 17 00:00:00 2001 From: jasquat <2487833+jasquat@users.noreply.github.com> Date: Mon, 17 Jul 2023 12:44:32 -0400 Subject: [PATCH] added uniqueness constraint to human task so it cannot have multiple human tasks for a process instance and task id w/ burnettk (#396) Co-authored-by: jasquat --- .../migrations/versions/56e17aab85ca_.py | 32 +++++++++++++++++++ .../models/human_task.py | 8 +++++ 2 files changed, 40 insertions(+) create mode 100644 spiffworkflow-backend/migrations/versions/56e17aab85ca_.py diff --git a/spiffworkflow-backend/migrations/versions/56e17aab85ca_.py b/spiffworkflow-backend/migrations/versions/56e17aab85ca_.py new file mode 100644 index 00000000..79a029f7 --- /dev/null +++ b/spiffworkflow-backend/migrations/versions/56e17aab85ca_.py @@ -0,0 +1,32 @@ +"""empty message + +Revision ID: 56e17aab85ca +Revises: 64adf34a98db +Create Date: 2023-07-14 11:54:20.187703 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '56e17aab85ca' +down_revision = '64adf34a98db' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('human_task', schema=None) as batch_op: + batch_op.create_unique_constraint('process_instance_task_unique', ['process_instance_id', 'task_id']) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('human_task', schema=None) as batch_op: + batch_op.drop_constraint('process_instance_task_unique', type_='unique') + + # ### end Alembic commands ### diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task.py index e2d017a4..4aa835ce 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task.py @@ -23,6 +23,14 @@ if TYPE_CHECKING: class HumanTaskModel(SpiffworkflowBaseDBModel): __tablename__ = "human_task" + __table_args__ = ( + db.UniqueConstraint( + "process_instance_id", + "task_id", + name="process_instance_task_unique", + ), + ) + id: int = db.Column(db.Integer, primary_key=True) process_instance_id: int = db.Column( ForeignKey(ProcessInstanceModel.id), nullable=False, index=True # type: ignore