From 37b735b98869c9ce3cd80cf8814be8c271aeb5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 5 Feb 2025 17:21:36 +0100 Subject: [PATCH 1/2] feat: refs #8535 sistema de warnings --- .../vn/triggers/mandate_afterDelete.sql | 12 ++++++++++ .../vn/triggers/mandate_beforeInsert.sql | 10 ++++---- .../vn/triggers/mandate_beforeUpdate.sql | 8 +++++++ .../11432-yellowRoebelini/00-firstScript.sql | 23 +++++++++++++++++++ .../client/back/locale/client-sample/es.yml | 2 +- modules/client/back/locale/mandate/en.yml | 10 ++++++++ modules/client/back/locale/mandate/es.yml | 10 ++++++++ modules/client/back/models/mandate.json | 5 +++- 8 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 db/routines/vn/triggers/mandate_afterDelete.sql create mode 100644 db/routines/vn/triggers/mandate_beforeUpdate.sql create mode 100644 db/versions/11432-yellowRoebelini/00-firstScript.sql create mode 100644 modules/client/back/locale/mandate/en.yml create mode 100644 modules/client/back/locale/mandate/es.yml diff --git a/db/routines/vn/triggers/mandate_afterDelete.sql b/db/routines/vn/triggers/mandate_afterDelete.sql new file mode 100644 index 0000000000..6ef27bb108 --- /dev/null +++ b/db/routines/vn/triggers/mandate_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`mandate_afterDelete` + AFTER DELETE ON `mandate` + FOR EACH ROW +BEGIN + INSERT INTO mandateLog + SET `action` = 'delete', + `changedModel` = 'mandate', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/mandate_beforeInsert.sql b/db/routines/vn/triggers/mandate_beforeInsert.sql index bfc36cc31f..6fe26604aa 100644 --- a/db/routines/vn/triggers/mandate_beforeInsert.sql +++ b/db/routines/vn/triggers/mandate_beforeInsert.sql @@ -4,9 +4,11 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`mandate_beforeInsert` FOR EACH ROW BEGIN IF (NEW.code IS NULL) THEN - SET NEW.code=CONCAT(NEW.clientFk,'-',(SELECT AUTO_INCREMENT - FROM information_schema.TABLES - WHERE TABLE_SCHEMA='vn' and TABLE_NAME='mandate')); - END IF; + SET NEW.code=CONCAT(NEW.clientFk,'-',(SELECT AUTO_INCREMENT + FROM information_schema.TABLES + WHERE TABLE_SCHEMA='vn' and TABLE_NAME='mandate')); + END IF; + + SET NEW.editorFk = account.myUser_getId(); END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/mandate_beforeUpdate.sql b/db/routines/vn/triggers/mandate_beforeUpdate.sql new file mode 100644 index 0000000000..0932fda393 --- /dev/null +++ b/db/routines/vn/triggers/mandate_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`mandate_beforeUpdate` + BEFORE INSERT ON `mandate` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/versions/11432-yellowRoebelini/00-firstScript.sql b/db/versions/11432-yellowRoebelini/00-firstScript.sql new file mode 100644 index 0000000000..15652d3375 --- /dev/null +++ b/db/versions/11432-yellowRoebelini/00-firstScript.sql @@ -0,0 +1,23 @@ +CREATE OR REPLACE TABLE vn.mandateLog ( + `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('client') NOT NULL DEFAULT 'client', + `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, + `summaryId` varchar(30) DEFAULT NULL, + `reason` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `logMandate_userFk` (`userFk`), + KEY `mandateLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), + KEY `mandateLog_originFk` (`originFk`,`creationDate`), + KEY `mandateLog_creationDate_IDX` (`creationDate` DESC) USING BTREE, + CONSTRAINT `mandateUserFk` 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; + +ALTER TABLE vn.mandate ADD editorFk INT UNSIGNED DEFAULT NULL NULL; diff --git a/modules/client/back/locale/client-sample/es.yml b/modules/client/back/locale/client-sample/es.yml index 5293adaa8b..5f400c8687 100644 --- a/modules/client/back/locale/client-sample/es.yml +++ b/modules/client/back/locale/client-sample/es.yml @@ -1,4 +1,4 @@ -name: muestra +name: plantilla columns: id: id created: creado diff --git a/modules/client/back/locale/mandate/en.yml b/modules/client/back/locale/mandate/en.yml new file mode 100644 index 0000000000..6a43ebb5e1 --- /dev/null +++ b/modules/client/back/locale/mandate/en.yml @@ -0,0 +1,10 @@ +name: mandate +columns: + id: id + clientFk: client + companyFk: company + code: code + created: created + finished: finished + mandateTypeFk: mandate type + editorFk: editor diff --git a/modules/client/back/locale/mandate/es.yml b/modules/client/back/locale/mandate/es.yml new file mode 100644 index 0000000000..efe6465dc2 --- /dev/null +++ b/modules/client/back/locale/mandate/es.yml @@ -0,0 +1,10 @@ +name: mandate +columns: + id: id + clientFk: cliente + companyFk: empresa + code: código + created: creado + finished: finalizado + mandateTypeFk: tipo de mandato + editorFk: editor diff --git a/modules/client/back/models/mandate.json b/modules/client/back/models/mandate.json index 914b23ce27..89a18fd7e2 100644 --- a/modules/client/back/models/mandate.json +++ b/modules/client/back/models/mandate.json @@ -1,6 +1,9 @@ { "name": "Mandate", "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "mandate" @@ -39,4 +42,4 @@ "foreignKey": "mandateTypeFk" } } - } \ No newline at end of file + } -- 2.40.1 From 9b2c0f1c487c957febd5fbcb9990f265c08d7a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 6 Feb 2025 11:46:39 +0100 Subject: [PATCH 2/2] feat: refs #8535 log table mandate --- db/routines/vn/triggers/mandate_beforeInsert.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/triggers/mandate_beforeInsert.sql b/db/routines/vn/triggers/mandate_beforeInsert.sql index 6fe26604aa..090133eef1 100644 --- a/db/routines/vn/triggers/mandate_beforeInsert.sql +++ b/db/routines/vn/triggers/mandate_beforeInsert.sql @@ -3,12 +3,12 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`mandate_beforeInsert` BEFORE INSERT ON `mandate` FOR EACH ROW BEGIN + SET NEW.editorFk = account.myUser_getId(); + IF (NEW.code IS NULL) THEN SET NEW.code=CONCAT(NEW.clientFk,'-',(SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA='vn' and TABLE_NAME='mandate')); END IF; - - SET NEW.editorFk = account.myUser_getId(); END$$ DELIMITER ; -- 2.40.1