Files
alfresco-community-repo/config/alfresco/dbscripts/upgrade/4.2/org.hibernate.dialect.MySQLInnoDBDialect/migrate-activiti-workflows.sql
Andrei Rebegea 01454653d3 Merged 5.0.N (5.0.4) to 5.1.N (5.1.1)
122111 arebegea: Merged V4.2-BUG-FIX (4.2.7) to 5.0.N (5.0.4)
      122110 arebegea: Merged V4.2.6 (4.2.6) to V4.2-BUG-FIX (4.2.7)
         122020 aleahu: MNT-15144 : Workflow filters are not working for the activiti workflows after upgrade from 4.1.10
            - Added an upgrade script that moves missing workflow variables from act_hi_detail to act_hi_varinst
            - Only the most recent version of a workflow variable should be moved to act_hi_varinst, only if not already present
            


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@122118 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2016-02-11 16:07:15 +00:00

76 lines
2.5 KiB
SQL

--
-- Title: Migrate old workflow details into act_hi_varinst
-- Database: MySQL
-- Since: V4.2 Schema 6080
--
-- Please contact support@alfresco.com if you need assistance with the upgrade.
--
-- Migrate old workflow details into act_hi_varinst
--ASSIGN:START_INDEX=VALUE_
SELECT VALUE_ FROM act_ge_property WHERE NAME_ = 'next.dbid';
--count the current items in act_hi_varinst, before migration
--ASSIGN:INITIAL_ROW_COUNT=ROW_COUNT
select count(*) as ROW_COUNT from act_hi_varinst;
-- insert from act_hi_detail into act_hi_varinst, the id will be generated starting from the next.dbid
-- only the most recent version of a variable must by migrated
-- the most recent version of a variable is considered the be the one with the highest revision and timestamp
INSERT INTO act_hi_varinst(
ID_,
PROC_INST_ID_,
EXECUTION_ID_,
TASK_ID_,
NAME_,
VAR_TYPE_,
REV_,
BYTEARRAY_ID_,
DOUBLE_,
LONG_,
TEXT_,
TEXT2_
)
SELECT
(@cnt := @cnt + 1),
PROC_INST_ID_,
EXECUTION_ID_,
TASK_ID_,
NAME_,
VAR_TYPE_,
REV_,
BYTEARRAY_ID_,
DOUBLE_,
LONG_,
TEXT_,
TEXT2_
FROM ACT_HI_DETAIL AHD
CROSS JOIN (SELECT @cnt := ${START_INDEX} + 1) AS dummy
WHERE AHD.PROC_INST_ID_ not in (select PROC_INST_ID_ from ACT_HI_VARINST)
AND
(AHD.PROC_INST_ID_ , AHD.NAME_, AHD.REV_, AHD.time_) IN
(SELECT PROC_INST_ID_, NAME_, MAX(REV_), MAX(time_)
FROM ACT_HI_DETAIL
GROUP BY PROC_INST_ID_ , NAME_);
--update act_ge_property
--ASSIGN:TOTAL_ROW_COUNT=ROW_COUNT
select count(*) as ROW_COUNT from act_hi_varinst;
--increase the next.dbid value so that following ids will be created starting with the new value
update act_ge_property set value_ = value_ + ${TOTAL_ROW_COUNT} - ${INITIAL_ROW_COUNT} where NAME_ = 'next.dbid';
--revision is currently increased each time a block id is reserved, so we're simulating this behaviour
update act_ge_property set rev_ = value_ DIV 100 + 1 where NAME_ = 'next.dbid';
--
-- Record script finish
--
DELETE FROM alf_applied_patch WHERE id = 'patch.db-v4.2-migrate-activiti-workflows';
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-v4.2-migrate-activiti-workflows', 'Manually executed script upgrade V4.2: migrate-activiti-workflows',
0, 6080, -1, 6081, null, 'UNKNOWN', ${TRUE}, ${TRUE}, 'Script completed'
);