From 85d68890b898b7d3189f487ca2698dd4e9602b62 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 3 Jun 2024 12:11:26 +0200 Subject: [PATCH 1/2] refactor: refs #6701 New table clientRate --- db/routines/vn/triggers/claimRatio_afterInsert.sql | 9 +++++++++ db/versions/11084-whitePalmetto/00-firstScript.sql | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 db/routines/vn/triggers/claimRatio_afterInsert.sql create mode 100644 db/versions/11084-whitePalmetto/00-firstScript.sql diff --git a/db/routines/vn/triggers/claimRatio_afterInsert.sql b/db/routines/vn/triggers/claimRatio_afterInsert.sql new file mode 100644 index 000000000..080e636a2 --- /dev/null +++ b/db/routines/vn/triggers/claimRatio_afterInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimRatio_afterInsert` + AFTER INSERT ON `claimRatio` + FOR EACH ROW +BEGIN + INSERT INTO clientRate(clientFk, `value`) + VALUES(NEW.clientFk, NEW.priceIncreasing); +END$$ +DELIMITER ; diff --git a/db/versions/11084-whitePalmetto/00-firstScript.sql b/db/versions/11084-whitePalmetto/00-firstScript.sql new file mode 100644 index 000000000..c5f841ea4 --- /dev/null +++ b/db/versions/11084-whitePalmetto/00-firstScript.sql @@ -0,0 +1,9 @@ +CREATE TABLE `vn`.`clientRate` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `clientFk` int(11) NOT NULL, + `dated` date NOT NULL DEFAULT current_timestamp(), + `value` decimal(10,2) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `clientRate_unique` (`clientFk`,`dated`), + CONSTRAINT `clientRate_client_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file From d3584691fa1f88e7addef2e15323f61914720be4 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 3 Jun 2024 12:16:33 +0200 Subject: [PATCH 2/2] refactor: refs #6701 Minor change --- db/routines/vn/triggers/claimRatio_afterInsert.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/triggers/claimRatio_afterInsert.sql b/db/routines/vn/triggers/claimRatio_afterInsert.sql index 080e636a2..ca618bb89 100644 --- a/db/routines/vn/triggers/claimRatio_afterInsert.sql +++ b/db/routines/vn/triggers/claimRatio_afterInsert.sql @@ -4,6 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimRatio_afterInser FOR EACH ROW BEGIN INSERT INTO clientRate(clientFk, `value`) - VALUES(NEW.clientFk, NEW.priceIncreasing); + VALUES(NEW.clientFk, NEW.priceIncreasing) + ON DUPLICATE KEY UPDATE + `value` = VALUES(`value`); END$$ DELIMITER ;