--
-- Title:      Upgrade to V3.4 - Add indexes for jbpm foreign keys
-- Database:   Generic
-- Since:      V3.4 schema 4204
-- Author:     pavelyur
--
-- Please contact support@alfresco.com if you need assistance with the upgrade.
--

CREATE INDEX FK_ACTION_REFACT ON JBPM_ACTION (REFERENCEDACTION_); --(optional)
CREATE INDEX FK_CRTETIMERACT_TA ON JBPM_ACTION (TIMERACTION_); --(optional)
CREATE INDEX FK_ACTION_PROCDEF ON JBPM_ACTION (PROCESSDEFINITION_); --(optional)
CREATE INDEX FK_ACTION_EVENT ON JBPM_ACTION (EVENT_); --(optional)
CREATE INDEX FK_ACTION_ACTNDEL ON JBPM_ACTION (ACTIONDELEGATION_); --(optional)
CREATE INDEX FK_ACTION_EXPTHDL ON  JBPM_ACTION(EXCEPTIONHANDLER_); --(optional)
CREATE INDEX FK_BYTEARR_FILDEF ON JBPM_BYTEARRAY (FILEDEFINITION_); --(optional)
CREATE INDEX FK_BYTEBLOCK_FILE ON JBPM_BYTEBLOCK (PROCESSFILE_); --(optional)
CREATE INDEX FK_COMMENT_TOKEN ON JBPM_COMMENT (TOKEN_); --(optional)
CREATE INDEX FK_COMMENT_TSK ON JBPM_COMMENT (TASKINSTANCE_); --(optional)
CREATE INDEX FK_DECCOND_DEC ON JBPM_DECISIONCONDITIONS (DECISION_); --(optional)
CREATE INDEX FK_DELEGATION_PRCD ON JBPM_DELEGATION (PROCESSDEFINITION_); --(optional)
CREATE INDEX FK_EVENT_PROCDEF ON JBPM_EVENT (PROCESSDEFINITION_); --(optional)
CREATE INDEX FK_EVENT_TRANS ON JBPM_EVENT (TRANSITION_); --(optional)
CREATE INDEX FK_EVENT_NODE ON JBPM_EVENT (NODE_); --(optional)
CREATE INDEX FK_EVENT_TASK ON JBPM_EVENT (TASK_); --(optional)
CREATE INDEX FK_JOB_PRINST ON JBPM_JOB (PROCESSINSTANCE_); --(optional)
CREATE INDEX FK_JOB_ACTION ON JBPM_JOB (ACTION_); --(optional)
CREATE INDEX FK_JOB_TOKEN ON JBPM_JOB (TOKEN_); --(optional)
CREATE INDEX FK_JOB_NODE ON JBPM_JOB (NODE_); --(optional)
CREATE INDEX FK_JOB_TSKINST ON JBPM_JOB (TASKINSTANCE_); --(optional)
CREATE INDEX FK_LOG_SOURCENODE ON JBPM_LOG (SOURCENODE_); --(optional)
CREATE INDEX FK_LOG_DESTNODE ON JBPM_LOG (DESTINATIONNODE_); --(optional)
CREATE INDEX FK_LOG_TOKEN ON JBPM_LOG (TOKEN_); --(optional)
CREATE INDEX FK_LOG_TRANSITION ON JBPM_LOG (TRANSITION_); --(optional)
CREATE INDEX FK_LOG_TASKINST ON JBPM_LOG (TASKINSTANCE_); --(optional)
CREATE INDEX FK_LOG_CHILDTOKEN ON JBPM_LOG (CHILD_); --(optional)
CREATE INDEX FK_LOG_OLDBYTES ON JBPM_LOG (OLDBYTEARRAY_); --(optional)
CREATE INDEX FK_LOG_SWIMINST ON JBPM_LOG (SWIMLANEINSTANCE_); --(optional)
CREATE INDEX FK_LOG_NEWBYTES ON JBPM_LOG (NEWBYTEARRAY_); --(optional)
CREATE INDEX FK_LOG_ACTION ON JBPM_LOG (ACTION_); --(optional)
CREATE INDEX FK_LOG_VARINST ON JBPM_LOG (VARIABLEINSTANCE_); --(optional)
CREATE INDEX FK_LOG_NODE ON JBPM_LOG (NODE_); --(optional)
CREATE INDEX FK_LOG_PARENT ON JBPM_LOG (PARENT_); --(optional)
CREATE INDEX FK_MODDEF_PROCDEF ON JBPM_MODULEDEFINITION (PROCESSDEFINITION_); --(optional)
CREATE INDEX FK_TSKDEF_START ON JBPM_MODULEDEFINITION (STARTTASK_); --(optional)
CREATE INDEX FK_MODINST_PRCINST ON JBPM_MODULEINSTANCE (PROCESSINSTANCE_); --(optional)
CREATE INDEX FK_TASKMGTINST_TMD ON JBPM_MODULEINSTANCE (TASKMGMTDEFINITION_); --(optional)
CREATE INDEX FK_DECISION_DELEG ON JBPM_NODE (DECISIONDELEGATION); --(optional)
CREATE INDEX FK_NODE_PROCDEF ON JBPM_NODE (PROCESSDEFINITION_); --(optional)
CREATE INDEX FK_NODE_ACTION ON JBPM_NODE (ACTION_); --(optional)
CREATE INDEX FK_PROCST_SBPRCDEF ON JBPM_NODE (SUBPROCESSDEFINITION_); --(optional)
CREATE INDEX FK_NODE_SCRIPT ON JBPM_NODE (SCRIPT_); --(optional)
CREATE INDEX FK_NODE_SUPERSTATE ON JBPM_NODE (SUPERSTATE_); --(optional)
CREATE INDEX FK_POOLEDACTOR_SLI ON JBPM_POOLEDACTOR (SWIMLANEINSTANCE_); --(optional)
CREATE INDEX FK_PROCDEF_STRTSTA ON JBPM_PROCESSDEFINITION (STARTSTATE_); --(optional)
CREATE INDEX FK_PROCIN_PROCDEF ON JBPM_PROCESSINSTANCE (PROCESSDEFINITION_); --(optional)
CREATE INDEX FK_PROCIN_ROOTTKN ON JBPM_PROCESSINSTANCE (ROOTTOKEN_); --(optional)
CREATE INDEX FK_PROCIN_SPROCTKN ON JBPM_PROCESSINSTANCE (SUPERPROCESSTOKEN_); --(optional)
CREATE INDEX FK_RTACTN_PROCINST ON JBPM_RUNTIMEACTION (PROCESSINSTANCE_); --(optional)
CREATE INDEX FK_RTACTN_ACTION ON JBPM_RUNTIMEACTION (ACTION_); --(optional)
CREATE INDEX FK_SWL_ASSDEL ON JBPM_SWIMLANE (ASSIGNMENTDELEGATION_); --(optional)
CREATE INDEX FK_SWL_TSKMGMTDEF ON JBPM_SWIMLANE (TASKMGMTDEFINITION_); --(optional)
CREATE INDEX FK_SWIMLANEINST_TM ON JBPM_SWIMLANEINSTANCE (TASKMGMTINSTANCE_); --(optional)
CREATE INDEX FK_SWIMLANEINST_SL ON JBPM_SWIMLANEINSTANCE (SWIMLANE_); --(optional)
CREATE INDEX FK_TASK_STARTST ON JBPM_TASK (STARTSTATE_); --(optional)
CREATE INDEX FK_TASK_PROCDEF ON JBPM_TASK (PROCESSDEFINITION_); --(optional)
CREATE INDEX FK_TASK_ASSDEL ON JBPM_TASK (ASSIGNMENTDELEGATION_); --(optional)
CREATE INDEX FK_TASK_SWIMLANE ON JBPM_TASK (SWIMLANE_); --(optional)
CREATE INDEX FK_TASK_TASKNODE ON JBPM_TASK (TASKNODE_); --(optional)
CREATE INDEX FK_TASK_TASKMGTDEF ON JBPM_TASK (TASKMGMTDEFINITION_); --(optional)
CREATE INDEX FK_TSK_TSKCTRL ON JBPM_TASK (TASKCONTROLLER_); --(optional)
CREATE INDEX FK_TASKACTPL_TSKI ON JBPM_TASKACTORPOOL (TASKINSTANCE_); --(optional)
CREATE INDEX FK_TSKACTPOL_PLACT ON JBPM_TASKACTORPOOL (POOLEDACTOR_); --(optional)
CREATE INDEX FK_TSKCTRL_DELEG ON JBPM_TASKCONTROLLER (TASKCONTROLLERDELEGATION_); --(optional)
CREATE INDEX FK_TSKINS_PRCINS ON JBPM_TASKINSTANCE (PROCINST_); --(optional)
CREATE INDEX FK_TASKINST_TMINST ON JBPM_TASKINSTANCE (TASKMGMTINSTANCE_); --(optional)
CREATE INDEX FK_TASKINST_TOKEN ON JBPM_TASKINSTANCE (TOKEN_); --(optional)
CREATE INDEX FK_TASKINST_SLINST ON JBPM_TASKINSTANCE (SWIMLANINSTANCE_); --(optional)
CREATE INDEX FK_TASKINST_TASK ON JBPM_TASKINSTANCE (TASK_); --(optional)
CREATE INDEX FK_TOKEN_SUBPI ON JBPM_TOKEN (SUBPROCESSINSTANCE_); --(optional)
CREATE INDEX FK_TOKEN_PROCINST ON JBPM_TOKEN (PROCESSINSTANCE_); --(optional)
CREATE INDEX FK_TOKEN_NODE ON JBPM_TOKEN (NODE_); --(optional)
CREATE INDEX FK_TOKEN_PARENT ON JBPM_TOKEN (PARENT_); --(optional)
CREATE INDEX FK_TKVARMAP_TOKEN ON JBPM_TOKENVARIABLEMAP (TOKEN_); --(optional)
CREATE INDEX FK_TKVARMAP_CTXT ON JBPM_TOKENVARIABLEMAP (CONTEXTINSTANCE_); --(optional)
CREATE INDEX FK_TRANSITION_FROM ON JBPM_TRANSITION (FROM_); --(optional)
CREATE INDEX FK_TRANS_PROCDEF ON JBPM_TRANSITION (PROCESSDEFINITION_); --(optional)
CREATE INDEX FK_TRANSITION_TO ON JBPM_TRANSITION (TO_); --(optional)
CREATE INDEX FK_VARACC_PROCST ON JBPM_VARIABLEACCESS (PROCESSSTATE_); --(optional)
CREATE INDEX FK_VARACC_SCRIPT ON JBPM_VARIABLEACCESS (SCRIPT_); --(optional)
CREATE INDEX FK_VARACC_TSKCTRL ON JBPM_VARIABLEACCESS (TASKCONTROLLER_); --(optional)
CREATE INDEX FK_VARINST_PRCINST ON JBPM_VARIABLEINSTANCE (PROCESSINSTANCE_); --(optional)
CREATE INDEX FK_VARINST_TKVARMP ON JBPM_VARIABLEINSTANCE (TOKENVARIABLEMAP_); --(optional)
CREATE INDEX FK_VARINST_TK ON JBPM_VARIABLEINSTANCE (TOKEN_); --(optional)
CREATE INDEX FK_BYTEINST_ARRAY ON JBPM_VARIABLEINSTANCE (BYTEARRAYVALUE_); --(optional)
CREATE INDEX FK_VAR_TSKINST ON JBPM_VARIABLEINSTANCE (TASKINSTANCE_); --(optional)


--
-- Record script finish
--
DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.4-JBPM-FK-indexes';
INSERT INTO alf_applied_patch
  (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report)
  VALUES
  (
    'patch.db-V3.4-JBPM-FK-indexes', 'Manually executed script upgrade to add FK indexes for JBPM',
     0, 4305, -1, 4306, null, 'UNKOWN', ${TRUE}, ${TRUE}, 'Script completed'
   );
