From 54ce5a7e16bc0a826f3c29a5e754e31cac308aad Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 29 Mar 2018 11:03:34 +0200 Subject: [PATCH] adding sql statements for updating to new workflow layout --- install/update-6.0.0/update-postgres.sql | 24 ++++++++++++++++ install/update-6.0.0/update-sqlite3.sql | 35 ++++++++++++++++++++++++ install/update-6.0.0/update.sql | 8 +++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/install/update-6.0.0/update-postgres.sql b/install/update-6.0.0/update-postgres.sql index aa0068bac..cf5a4c3fd 100644 --- a/install/update-6.0.0/update-postgres.sql +++ b/install/update-6.0.0/update-postgres.sql @@ -6,6 +6,30 @@ ALTER TABLE "tblUsers" ADD COLUMN "secret" varchar(50) default NULL; ALTER TABLE "tblWorkflows" ADD COLUMN "layoutdata" text default NULL; +ALTER TABLE "tblWorkflowDocumentContent" ADD COLUMN "id" SERIAL UNIQUE; + +ALTER TABLE "tblWorkflowLog" ADD COLUMN "workflowdocumentcontent" INTEGER NOT NULL DEFAULT '0'; + +UPDATE "tblWorkflowLog" SET "workflowdocumentcontent" = "tblWorkflowDocumentContent"."id" FROM "tblWorkflowDocumentContent" WHERE "tblWorkflowLog"."document" = "tblWorkflowDocumentContent"."document" AND "tblWorkflowLog"."version" = "tblWorkflowDocumentContent"."version" AND "tblWorkflowLog"."workflow" = "tblWorkflowDocumentContent"."workflow"; + +INSERT INTO "tblWorkflowDocumentContent" ("parentworkflow", "workflow", "document", "version", "state", "date") SELECT 0 AS "parentworkflow", "workflow", "document", "version", NULL AS "state", max("date") AS "date" FROM "tblWorkflowLog" WHERE "workflowdocumentcontent" = 0 GROUP BY "workflow", "document", "version"; + +UPDATE "tblWorkflowLog" SET "workflowdocumentcontent" = "tblWorkflowDocumentContent"."id" FROM "tblWorkflowDocumentContent" WHERE "tblWorkflowLog"."document" = "tblWorkflowDocumentContent"."document" AND "tblWorkflowLog"."version" = "tblWorkflowDocumentContent"."version" AND "tblWorkflowLog"."workflow" = "tblWorkflowDocumentContent"."workflow"; + +ALTER TABLE "tblWorkflowLog" ADD CONSTRAINT "tblWorkflowLog_workflowdocumentcontent" FOREIGN KEY ("workflowdocumentcontent") REFERENCES "tblWorkflowDocumentContent" ("id") ON DELETE CASCADE; + +ALTER TABLE "tblWorkflowDocumentContent" ADD COLUMN "parent" INTEGER DEFAULT NULL; + +ALTER TABLE "tblWorkflowDocumentContent" ADD CONSTRAINT "tblWorkflowDocumentContent_parent" FOREIGN KEY ("parent") REFERENCES "tblWorkflowDocumentContent" ("id") ON DELETE CASCADE; + +ALTER TABLE "tblWorkflowDocumentContent" DROP COLUMN "parentworkflow"; + +ALTER TABLE "tblWorkflowLog" DROP COLUMN "document"; + +ALTER TABLE "tblWorkflowLog" DROP COLUMN "version"; + +ALTER TABLE "tblWorkflowLog" DROP COLUMN "workflow"; + CREATE TABLE "tblUserSubstitutes" ( "id" SERIAL UNIQUE, "user" INTEGER default null, diff --git a/install/update-6.0.0/update-sqlite3.sql b/install/update-6.0.0/update-sqlite3.sql index c55358638..835206910 100644 --- a/install/update-6.0.0/update-sqlite3.sql +++ b/install/update-6.0.0/update-sqlite3.sql @@ -6,6 +6,39 @@ ALTER TABLE `tblUsers` ADD COLUMN `secret` varchar(50) default NULL; ALTER TABLE `tblWorkflows` ADD COLUMN `layoutdata` text default NULL; +CREATE TABLE `new_tblWorkflowDocumentContent` ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `parent` INTEGER DEFAULT NULL REFERENCES `new_tblWorkflowDocumentContent` (`id`) ON DELETE CASCADE, + `workflow` INTEGER DEFAULT NULL REFERENCES `tblWorkflows` (`id`) ON DELETE CASCADE, + `document` INTEGER DEFAULT NULL REFERENCES `tblDocuments` (`id`) ON DELETE CASCADE, + `version` INTEGER DEFAULT NULL, + `state` INTEGER DEFAULT NULL REFERENCES `tblWorkflowStates` (`id`) ON DELETE CASCADE, + `date` datetime NOT NULL +) ; + +INSERT INTO `new_tblWorkflowDocumentContent` (`parent`, `workflow`, `document`, `version`, `state`, `date`) SELECT NULL as `parent`, `workflow`, `document`, `version`, `state`, `date` FROM `tblWorkflowDocumentContent`; + +INSERT INTO `new_tblWorkflowDocumentContent` (`parent`, `workflow`, `document`, `version`, `state`, `date`) SELECT NULL, `a`.`workflow`, `a`.`document`, `a`.`version`, NULL AS `state`, max(`a`.`date`) FROM `tblWorkflowLog` `a` LEFT JOIN `tblWorkflowDocumentContent` `b` ON `a`.`document`=`b`.`document` AND `a`.`version`=`b`.`version` AND `a`.`workflow`=`b`.`workflow` WHERE `b`.`document` IS NULL GROUP BY `a`.`document`, `a`.`version`, `a`.`workflow`; + +CREATE TABLE `new_tblWorkflowLog` ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `workflowdocumentcontent` INTEGER DEFAULT NULL REFERENCES `new_tblWorkflowDocumentContent` (`id`) ON DELETE CASCADE, + `userid` INTEGER default NULL REFERENCES `tblUsers` (`id`) ON DELETE CASCADE, + `transition` INTEGER default NULL REFERENCES `tblWorkflowTransitions` (`id`) ON DELETE CASCADE, + `date` datetime NOT NULL, + `comment` text +) ; + +INSERT INTO `new_tblWorkflowLog` (`id`, `workflowdocumentcontent`, `userid`, `transition`, `date`, `comment`) SELECT `a`.`id`, `b`.`id`, `a`.`userid`, `a`.`transition`, `a`.`date`, `a`.`comment` FROM `tblWorkflowLog` `a` LEFT JOIN `new_tblWorkflowDocumentContent` `b` ON `a`.`document`=`b`.`document` AND `a`.`version`=`b`.`version` AND `a`.`workflow`=`b`.`workflow` WHERE `b`.`document` IS NOT NULL; + +DROP TABLE `tblWorkflowLog`; + +ALTER TABLE `new_tblWorkflowLog` RENAME TO `tblWorkflowLog`; + +DROP TABLE `tblWorkflowDocumentContent`; + +ALTER TABLE `new_tblWorkflowDocumentContent` RENAME TO `tblWorkflowDocumentContent`; + CREATE TABLE `tblUserSubstitutes` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `user` INTEGER NOT NULL default '0' REFERENCES `tblUsers` (`id`) ON DELETE CASCADE, @@ -121,6 +154,8 @@ ALTER TABLE tblUsers RENAME TO old_tblUsers; ALTER TABLE new_tblUsers RENAME TO tblUsers; +DROP TABLE old_tblUsers; + CREATE TABLE `tblAros` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `parent` INTEGER, diff --git a/install/update-6.0.0/update.sql b/install/update-6.0.0/update.sql index 0c71415fe..54bfe3430 100644 --- a/install/update-6.0.0/update.sql +++ b/install/update-6.0.0/update.sql @@ -12,7 +12,7 @@ ALTER TABLE `tblWorkflowLog` ADD COLUMN `workflowdocumentcontent` int(11) NOT NU UPDATE `tblWorkflowLog` a, `tblWorkflowDocumentContent` b SET a.`workflowdocumentcontent` = b.`id` WHERE a.`document` = b.`document` AND a.`version` = b.`version` AND a.`workflow` = b.`workflow`; -INSERT INTO `tblWorkflowDocumentContent` (`parentworkflow`, `workflow`, `document`, `version`, `state`, `date`) SELECT 0 as `parentworkflow`, `workflow`, `document`, `version`, NULL as `state`, max(`date`) as `date` FROM `tblWorkflowLog` WHERE `workflowdocumentcontent` = 0 GROUP BY `workflow`, `document`, `version`; +INSERT INTO `tblWorkflowDocumentContent` (`parentworkflow`, `workflow`, `document`, `version`, `state`, `date`) SELECT 0 AS `parentworkflow`, `workflow`, `document`, `version`, NULL AS `state`, max(`date`) AS `date` FROM `tblWorkflowLog` WHERE `workflowdocumentcontent` = 0 GROUP BY `workflow`, `document`, `version`; UPDATE `tblWorkflowLog` a, `tblWorkflowDocumentContent` b SET a.`workflowdocumentcontent` = b.`id` WHERE a.`document` = b.`document` AND a.`version` = b.`version` AND a.`workflow` = b.`workflow`; @@ -24,6 +24,12 @@ ALTER TABLE `tblWorkflowDocumentContent` ADD CONSTRAINT `tblWorkflowDocumentCont ALTER TABLE `tblWorkflowDocumentContent` DROP COLUMN `parentworkflow`; +ALTER TABLE `tblWorkflowLog` DROP COLUMN `document`; + +ALTER TABLE `tblWorkflowLog` DROP COLUMN `version`; + +ALTER TABLE `tblWorkflowLog` DROP COLUMN `workflow`; + CREATE TABLE `tblUserSubstitutes` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user` int(11) DEFAULT null,