From cf63d6e71c2d86bdb44f40f227da3ae49e02ce3e Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 11:17:33 +0200 Subject: [PATCH 1/2] feat: refs #7378 Added productionConfigLog --- .../triggers/productionConfig_afterDelete.sql | 12 ++++++++++ .../productionConfig_beforeInsert.sql | 8 +++++++ .../productionConfig_beforeUpdate.sql | 8 +++++++ .../11130-crimsonIvy/00-firstScript.sql | 23 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 db/routines/vn/triggers/productionConfig_afterDelete.sql create mode 100644 db/routines/vn/triggers/productionConfig_beforeInsert.sql create mode 100644 db/routines/vn/triggers/productionConfig_beforeUpdate.sql create mode 100644 db/versions/11130-crimsonIvy/00-firstScript.sql diff --git a/db/routines/vn/triggers/productionConfig_afterDelete.sql b/db/routines/vn/triggers/productionConfig_afterDelete.sql new file mode 100644 index 000000000..384bf681e --- /dev/null +++ b/db/routines/vn/triggers/productionConfig_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_afterDelete` + AFTER DELETE ON `productionConfig` + FOR EACH ROW +BEGIN + INSERT INTO productionConfig + SET `action` = 'delete', + `changedModel` = 'ProductionConfig', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/productionConfig_beforeInsert.sql b/db/routines/vn/triggers/productionConfig_beforeInsert.sql new file mode 100644 index 000000000..99b217be4 --- /dev/null +++ b/db/routines/vn/triggers/productionConfig_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_beforeInsert` + BEFORE INSERT ON `productionConfig` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/productionConfig_beforeUpdate.sql b/db/routines/vn/triggers/productionConfig_beforeUpdate.sql new file mode 100644 index 000000000..f1ceaa471 --- /dev/null +++ b/db/routines/vn/triggers/productionConfig_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_beforeUpdate` + BEFORE UPDATE ON `productionConfig` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/versions/11130-crimsonIvy/00-firstScript.sql b/db/versions/11130-crimsonIvy/00-firstScript.sql new file mode 100644 index 000000000..3bde55f55 --- /dev/null +++ b/db/versions/11130-crimsonIvy/00-firstScript.sql @@ -0,0 +1,23 @@ +ALTER TABLE vn.productionConfig + ADD editorFk int(10) unsigned DEFAULT NULL NULL; +ALTER TABLE vn.productionConfig + ADD CONSTRAINT productionConfig_user_FK FOREIGN KEY (editorFk) REFERENCES account.`user`(id); + +CREATE OR REPLACE TABLE `vn`.`productionConfigLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete','select') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` enum('ProductionConfig') NOT NULL DEFAULT 'ProductionConfig', + `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), + `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), + `changedModelId` int(11) NOT NULL, + `changedModelValue` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `logRateuserFk` (`userFk`), + KEY `productionConfigLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), + KEY `productionConfigLog_originFk` (`originFk`,`creationDate`), + CONSTRAINT `productionConfigUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; From 27f9001e344ca45654aa762c32564bbf44417c0f Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 11:35:05 +0200 Subject: [PATCH 2/2] refactor: refs #7378 Requested changes --- db/versions/11130-crimsonIvy/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11130-crimsonIvy/00-firstScript.sql b/db/versions/11130-crimsonIvy/00-firstScript.sql index 3bde55f55..c93f2f6b7 100644 --- a/db/versions/11130-crimsonIvy/00-firstScript.sql +++ b/db/versions/11130-crimsonIvy/00-firstScript.sql @@ -16,7 +16,7 @@ CREATE OR REPLACE TABLE `vn`.`productionConfigLog` ( `changedModelId` int(11) NOT NULL, `changedModelValue` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`), - KEY `logRateuserFk` (`userFk`), + KEY `productionConfigLog_userFk` (`userFk`), KEY `productionConfigLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), KEY `productionConfigLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `productionConfigUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE