diff --git a/config/alfresco/dbscripts/db-schema-context.xml b/config/alfresco/dbscripts/db-schema-context.xml index 676f47c338..04afc095ef 100644 --- a/config/alfresco/dbscripts/db-schema-context.xml +++ b/config/alfresco/dbscripts/db-schema-context.xml @@ -82,6 +82,7 @@ + diff --git a/config/alfresco/dbscripts/upgrade/4.2/org.hibernate.dialect.MySQLInnoDBDialect/migrate-activiti-workflows.sql b/config/alfresco/dbscripts/upgrade/4.2/org.hibernate.dialect.MySQLInnoDBDialect/migrate-activiti-workflows.sql new file mode 100644 index 0000000000..7f0c062cb5 --- /dev/null +++ b/config/alfresco/dbscripts/upgrade/4.2/org.hibernate.dialect.MySQLInnoDBDialect/migrate-activiti-workflows.sql @@ -0,0 +1,76 @@ +-- +-- 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' + ); \ No newline at end of file diff --git a/config/alfresco/dbscripts/upgrade/4.2/org.hibernate.dialect.PostgreSQLDialect/migrate-activiti-workflows.sql b/config/alfresco/dbscripts/upgrade/4.2/org.hibernate.dialect.PostgreSQLDialect/migrate-activiti-workflows.sql new file mode 100644 index 0000000000..2e55ff6959 --- /dev/null +++ b/config/alfresco/dbscripts/upgrade/4.2/org.hibernate.dialect.PostgreSQLDialect/migrate-activiti-workflows.sql @@ -0,0 +1,80 @@ +-- +-- Title: Migrate old workflow details into act_hi_varinst +-- Database: PostgreSQL +-- 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'; + +CREATE SEQUENCE VARINST_ID_SEQ START ${START_INDEX}; + +--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; + +-- increment the value to be used by the indexes with 1; +select nextval('VARINST_ID_SEQ'); + +-- 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 to 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 + nextval('VARINST_ID_SEQ'), + PROC_INST_ID_, + EXECUTION_ID_, + TASK_ID_, + NAME_, + VAR_TYPE_, + REV_, + BYTEARRAY_ID_, + DOUBLE_, + LONG_, + TEXT_, + TEXT2_ +FROM ACT_HI_DETAIL AHD +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_::integer + ${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_::integer / 100 + 1 where NAME_ = 'next.dbid'; + +DROP SEQUENCE IF EXISTS VARINST_ID_SEQ; +-- +-- 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' + ); \ No newline at end of file diff --git a/config/alfresco/messages/patch-service.properties b/config/alfresco/messages/patch-service.properties index 00fc3a58bb..3174e241fb 100644 --- a/config/alfresco/messages/patch-service.properties +++ b/config/alfresco/messages/patch-service.properties @@ -386,4 +386,6 @@ patch.addSurfConfigFolders.description=Adds 'cm:extensions' and 'cm:module-deplo patch.spacesBootstrapSmartDownloadFolder.description=Adds Smart Download Folder in Data Dictionary. patch.spacesBootstrapSmartTemplatesFolder.description=Adds Smart Templates Folder in Data Dictionary. -patch.spacesBootstrapSmartFolderExample.description=Adds smartFoldersExample.json file in Smart Templates Folder. \ No newline at end of file +patch.spacesBootstrapSmartFolderExample.description=Adds smartFoldersExample.json file in Smart Templates Folder. + +patch.db-v4.2-migrate-activiti-workflows.description=Migrated workflow variables into newly created table. \ No newline at end of file diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index a01340e20b..8edcceaa73 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -1415,4 +1415,15 @@ + + + patch.db-v4.2-migrate-activiti-workflows + patch.db-v4.2-migrate-activiti-workflows.description + 0 + 9027 + 9028 + + classpath:alfresco/dbscripts/upgrade/4.2/${db.script.dialect}/migrate-activiti-workflows.sql + + diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index 79137f6c30..72872548dd 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -23,4 +23,4 @@ version.build=r@scm-revision@-b@build-number@ # Schema number -version.schema=9027 +version.schema=9028