added indexes to foreign key fields w/ burnettk

This commit is contained in:
jasquat 2023-03-17 16:26:35 -04:00
parent 310c9535cf
commit 8b31f73797
No known key found for this signature in database
16 changed files with 28 additions and 28 deletions

View File

@ -20,11 +20,11 @@ class BpmnProcessModel(SpiffworkflowBaseDBModel):
guid: str | None = db.Column(db.String(36), nullable=True, unique=True, index=True)
bpmn_process_definition_id: int = db.Column(
ForeignKey(BpmnProcessDefinitionModel.id), nullable=False # type: ignore
ForeignKey(BpmnProcessDefinitionModel.id), nullable=False, index=True # type: ignore
)
bpmn_process_definition = relationship(BpmnProcessDefinitionModel)
parent_process_id: int | None = db.Column(ForeignKey("bpmn_process.id"), nullable=True)
parent_process_id: int | None = db.Column(ForeignKey("bpmn_process.id"), nullable=True, index=True)
properties_json: dict = db.Column(db.JSON, nullable=False)
json_data_hash: str = db.Column(db.String(255), nullable=False, index=True)

View File

@ -22,8 +22,8 @@ class BpmnProcessDefinitionRelationshipModel(SpiffworkflowBaseDBModel):
id: int = db.Column(db.Integer, primary_key=True)
bpmn_process_definition_parent_id: int = db.Column(
ForeignKey(BpmnProcessDefinitionModel.id), nullable=False # type: ignore
ForeignKey(BpmnProcessDefinitionModel.id), nullable=False, index=True # type: ignore
)
bpmn_process_definition_child_id: int = db.Column(
ForeignKey(BpmnProcessDefinitionModel.id), nullable=False # type: ignore
ForeignKey(BpmnProcessDefinitionModel.id), nullable=False, index=True # type: ignore
)

View File

@ -29,13 +29,13 @@ class HumanTaskModel(SpiffworkflowBaseDBModel):
__tablename__ = "human_task"
id: int = db.Column(db.Integer, primary_key=True)
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=False) # type: ignore
lane_assignment_id: int | None = db.Column(ForeignKey(GroupModel.id))
completed_by_user_id: int = db.Column(ForeignKey(UserModel.id), nullable=True) # type: ignore
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=False, index=True) # type: ignore
lane_assignment_id: int | None = db.Column(ForeignKey(GroupModel.id), index=True)
completed_by_user_id: int = db.Column(ForeignKey(UserModel.id), nullable=True, index=True) # type: ignore
completed_by_user = relationship("UserModel", foreign_keys=[completed_by_user_id], viewonly=True)
actual_owner_id: int = db.Column(ForeignKey(UserModel.id)) # type: ignore
actual_owner_id: int = db.Column(ForeignKey(UserModel.id), index=True) # type: ignore
# actual_owner: RelationshipProperty[UserModel] = relationship(UserModel)
form_file_name: str | None = db.Column(db.String(50))
@ -45,7 +45,7 @@ class HumanTaskModel(SpiffworkflowBaseDBModel):
created_at_in_seconds: int = db.Column(db.Integer)
# task_id came first which is why it's a string and task_model_id is the int and foreignkey
task_model_id: int = db.Column(ForeignKey(TaskModel.id), nullable=True) # type: ignore
task_model_id: int = db.Column(ForeignKey(TaskModel.id), nullable=True, index=True) # type: ignore
task_id: str = db.Column(db.String(50))
task_name: str = db.Column(db.String(255))
task_title: str = db.Column(db.String(50))

View File

@ -47,7 +47,7 @@ class MessageInstanceModel(SpiffworkflowBaseDBModel):
__tablename__ = "message_instance"
id: int = db.Column(db.Integer, primary_key=True)
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=True) # type: ignore
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=True, index=True) # type: ignore
name: str = db.Column(db.String(255))
message_type: str = db.Column(db.String(20), nullable=False)
# Only Send Messages have a payload
@ -55,7 +55,7 @@ class MessageInstanceModel(SpiffworkflowBaseDBModel):
# The correlation keys of the process at the time the message was created.
correlation_keys: dict = db.Column(db.JSON)
status: str = db.Column(db.String(20), nullable=False, default="ready")
user_id: int = db.Column(ForeignKey(UserModel.id), nullable=True) # type: ignore
user_id: int = db.Column(ForeignKey(UserModel.id), nullable=True, index=True) # type: ignore
user = relationship("UserModel")
counterpart_id: int = db.Column(
db.Integer

View File

@ -46,8 +46,8 @@ class PermissionAssignmentModel(SpiffworkflowBaseDBModel):
),
)
id = db.Column(db.Integer, primary_key=True)
principal_id = db.Column(ForeignKey(PrincipalModel.id), nullable=False)
permission_target_id = db.Column(ForeignKey(PermissionTargetModel.id), nullable=False) # type: ignore
principal_id = db.Column(ForeignKey(PrincipalModel.id), nullable=False, index=True)
permission_target_id = db.Column(ForeignKey(PermissionTargetModel.id), nullable=False, index=True) # type: ignore
grant_type = db.Column(db.String(50), nullable=False)
permission = db.Column(db.String(50), nullable=False)

View File

@ -57,14 +57,14 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel):
id: int = db.Column(db.Integer, primary_key=True)
process_model_identifier: str = db.Column(db.String(255), nullable=False, index=True)
process_model_display_name: str = db.Column(db.String(255), nullable=False, index=True)
process_initiator_id: int = db.Column(ForeignKey(UserModel.id), nullable=False) # type: ignore
process_initiator_id: int = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) # type: ignore
process_initiator = relationship("UserModel")
bpmn_process_definition_id: int | None = db.Column(
ForeignKey(BpmnProcessDefinitionModel.id), nullable=True, index=True # type: ignore
)
bpmn_process_definition = relationship(BpmnProcessDefinitionModel)
bpmn_process_id: int | None = db.Column(ForeignKey(BpmnProcessModel.id), nullable=True) # type: ignore
bpmn_process_id: int | None = db.Column(ForeignKey(BpmnProcessModel.id), nullable=True, index=True) # type: ignore
bpmn_process = relationship(BpmnProcessModel, cascade="delete")
tasks = relationship("TaskModel", cascade="delete") # type: ignore
process_instance_events = relationship("ProcessInstanceEventModel", cascade="delete") # type: ignore

View File

@ -30,7 +30,7 @@ class ProcessInstanceEventModel(SpiffworkflowBaseDBModel):
# use task guid so we can bulk insert without worrying about whether or not the task has an id yet
task_guid: str | None = db.Column(db.String(36), nullable=True, index=True)
process_instance_id: int = db.Column(ForeignKey("process_instance.id"), nullable=False)
process_instance_id: int = db.Column(ForeignKey("process_instance.id"), nullable=False, index=True)
event_type: str = db.Column(db.String(50), nullable=False, index=True)
timestamp: float = db.Column(db.DECIMAL(17, 6), nullable=False, index=True)

View File

@ -17,7 +17,7 @@ class ProcessInstanceFileDataModel(SpiffworkflowBaseDBModel):
__tablename__ = "process_instance_file_data"
id: int = db.Column(db.Integer, primary_key=True)
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=False) # type: ignore
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=False, index=True) # type: ignore
identifier: str = db.Column(db.String(255), nullable=False)
list_index: Optional[int] = db.Column(db.Integer, nullable=True)
mimetype: str = db.Column(db.String(255), nullable=False)

View File

@ -16,7 +16,7 @@ class ProcessInstanceMetadataModel(SpiffworkflowBaseDBModel):
__table_args__ = (db.UniqueConstraint("process_instance_id", "key", name="process_instance_metadata_unique"),)
id: int = db.Column(db.Integer, primary_key=True)
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=False) # type: ignore
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=False, index=True) # type: ignore
key: str = db.Column(db.String(255), nullable=False, index=True)
value: str = db.Column(db.String(255), nullable=False)

View File

@ -17,7 +17,7 @@ class ProcessInstanceQueueModel(SpiffworkflowBaseDBModel):
id: int = db.Column(db.Integer, primary_key=True)
process_instance_id: int = db.Column(
ForeignKey(ProcessInstanceModel.id), index=True, unique=True, nullable=False # type: ignore
ForeignKey(ProcessInstanceModel.id), index=True, unique=True, nullable=False, index=True # type: ignore
)
run_at_in_seconds: int = db.Column(db.Integer)
priority: int = db.Column(db.Integer)

View File

@ -17,7 +17,7 @@ class SecretModel(SpiffworkflowBaseDBModel):
id: int = db.Column(db.Integer, primary_key=True)
key: str = db.Column(db.String(50), unique=True, nullable=False)
value: str = db.Column(db.Text(), nullable=False)
user_id: int = db.Column(ForeignKey(UserModel.id), nullable=False) # type: ignore
user_id: int = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) # type: ignore
updated_at_in_seconds: int = db.Column(db.Integer)
created_at_in_seconds: int = db.Column(db.Integer)

View File

@ -19,7 +19,7 @@ class SpiffStepDetailsModel(SpiffworkflowBaseDBModel):
__table_args__ = (UniqueConstraint("process_instance_id", "spiff_step", name="process_instance_id_spiff_step"),)
id: int = db.Column(db.Integer, primary_key=True)
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=False) # type: ignore
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=False, index=True) # type: ignore
spiff_step: int = db.Column(db.Integer, nullable=False)
task_json: dict = deferred(db.Column(db.JSON, nullable=False)) # type: ignore
task_id: str = db.Column(db.String(50), nullable=False)

View File

@ -49,12 +49,12 @@ class TaskModel(SpiffworkflowBaseDBModel):
__tablename__ = "task"
id: int = db.Column(db.Integer, primary_key=True)
guid: str = db.Column(db.String(36), nullable=False, unique=True, index=True)
bpmn_process_id: int = db.Column(ForeignKey(BpmnProcessModel.id), nullable=False) # type: ignore
bpmn_process_id: int = db.Column(ForeignKey(BpmnProcessModel.id), nullable=False, index=True) # type: ignore
bpmn_process = relationship(BpmnProcessModel, back_populates="tasks")
process_instance_id: int = db.Column(ForeignKey("process_instance.id"), nullable=False)
process_instance_id: int = db.Column(ForeignKey("process_instance.id"), nullable=False, index=True)
# find this by looking up the "workflow_name" and "task_spec" from the properties_json
task_definition_id: int = db.Column(ForeignKey(TaskDefinitionModel.id), nullable=False) # type: ignore
task_definition_id: int = db.Column(ForeignKey(TaskDefinitionModel.id), nullable=False, index=True) # type: ignore
task_definition = relationship("TaskDefinitionModel")
state: str = db.Column(db.String(10), nullable=False)

View File

@ -23,7 +23,7 @@ class TaskDefinitionModel(SpiffworkflowBaseDBModel):
id: int = db.Column(db.Integer, primary_key=True)
bpmn_process_definition_id: int = db.Column(
ForeignKey(BpmnProcessDefinitionModel.id), nullable=False # type: ignore
ForeignKey(BpmnProcessDefinitionModel.id), nullable=False, index=True # type: ignore
)
bpmn_process_definition = relationship(BpmnProcessDefinitionModel)

View File

@ -15,8 +15,8 @@ class UserGroupAssignmentModel(SpiffworkflowBaseDBModel):
__table_args__ = (db.UniqueConstraint("user_id", "group_id", name="user_group_assignment_unique"),)
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(ForeignKey(UserModel.id), nullable=False) # type: ignore
group_id = db.Column(ForeignKey(GroupModel.id), nullable=False)
user_id = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) # type: ignore
group_id = db.Column(ForeignKey(GroupModel.id), nullable=False, index=True)
group = relationship("GroupModel", overlaps="groups,user_group_assignments,users") # type: ignore
user = relationship("UserModel", overlaps="groups,user_group_assignments,users") # type: ignore

View File

@ -19,7 +19,7 @@ class UserGroupAssignmentWaitingModel(SpiffworkflowBaseDBModel):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(255), nullable=False)
group_id = db.Column(ForeignKey(GroupModel.id), nullable=False)
group_id = db.Column(ForeignKey(GroupModel.id), nullable=False, index=True)
group = relationship("GroupModel", overlaps="groups,user_group_assignments_waiting,users") # type: ignore