From 1a1e7742d3ea5be78389d11d8f39a14b3ce79b34 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 23 Feb 2024 15:32:21 +0100 Subject: [PATCH 1/3] feat: refs #6513 create table --- .../10908-blueAsparagus/00-createSupplierDms.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 db/versions/10908-blueAsparagus/00-createSupplierDms.sql diff --git a/db/versions/10908-blueAsparagus/00-createSupplierDms.sql b/db/versions/10908-blueAsparagus/00-createSupplierDms.sql new file mode 100644 index 000000000..fb592db0d --- /dev/null +++ b/db/versions/10908-blueAsparagus/00-createSupplierDms.sql @@ -0,0 +1,10 @@ +CREATE TABLE IF NOT EXISTS vn.supplierDms( + id int(11) NOT NULL AUTO_INCREMENT, + supplierFk int(11) NOT NULL, + dmsFk int(11) NOT NULL, + editorFk int(10) unsigned DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT clientDms_fk_editor FOREIGN KEY (editorFk) REFERENCES account.user(id), + CONSTRAINT dmsFk FOREIGN KEY (dmsFk) REFERENCES dms(id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT supplierFk FOREIGN KEY (supplierFk) REFERENCES supplier(id) ON UPDATE CASCADE +); -- 2.40.1 From 3c038a060cd0cf98d641aab1e1487584259047a4 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 23 Feb 2024 16:27:49 +0100 Subject: [PATCH 2/3] feat: refs #6513 WIP triggers & logger --- db/routines/vn/triggers/supplierDms_afterDelete.sql | 12 ++++++++++++ db/routines/vn/triggers/supplierDms_beforeInsert.sql | 8 ++++++++ db/routines/vn/triggers/supplierDms_beforeUpdate.sql | 8 ++++++++ .../10908-blueAsparagus/00-createSupplierDms.sql | 9 ++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 db/routines/vn/triggers/supplierDms_afterDelete.sql create mode 100644 db/routines/vn/triggers/supplierDms_beforeInsert.sql create mode 100644 db/routines/vn/triggers/supplierDms_beforeUpdate.sql diff --git a/db/routines/vn/triggers/supplierDms_afterDelete.sql b/db/routines/vn/triggers/supplierDms_afterDelete.sql new file mode 100644 index 000000000..482decbb6 --- /dev/null +++ b/db/routines/vn/triggers/supplierDms_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierDms_afterDelete` + AFTER DELETE ON `supplierDms` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'supplierDms', + `changedModelId` = OLD.dmsFk, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/supplierDms_beforeInsert.sql b/db/routines/vn/triggers/supplierDms_beforeInsert.sql new file mode 100644 index 000000000..adef31c2b --- /dev/null +++ b/db/routines/vn/triggers/supplierDms_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=root@localhost TRIGGER vn.supplierDms_beforeInsert + BEFORE INSERT ON supplierDms + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplierDms_beforeUpdate.sql b/db/routines/vn/triggers/supplierDms_beforeUpdate.sql new file mode 100644 index 000000000..228c5e5ea --- /dev/null +++ b/db/routines/vn/triggers/supplierDms_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=root@localhost TRIGGER vn.supplierDms_beforeUpdate + BEFORE UPDATE ON supplierDms + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/versions/10908-blueAsparagus/00-createSupplierDms.sql b/db/versions/10908-blueAsparagus/00-createSupplierDms.sql index fb592db0d..23c45cc7b 100644 --- a/db/versions/10908-blueAsparagus/00-createSupplierDms.sql +++ b/db/versions/10908-blueAsparagus/00-createSupplierDms.sql @@ -4,7 +4,14 @@ CREATE TABLE IF NOT EXISTS vn.supplierDms( dmsFk int(11) NOT NULL, editorFk int(10) unsigned DEFAULT NULL, PRIMARY KEY (id), - CONSTRAINT clientDms_fk_editor FOREIGN KEY (editorFk) REFERENCES account.user(id), + CONSTRAINT supplierDms_fk_editor FOREIGN KEY (editorFk) REFERENCES account.user(id), CONSTRAINT dmsFk FOREIGN KEY (dmsFk) REFERENCES dms(id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT supplierFk FOREIGN KEY (supplierFk) REFERENCES supplier(id) ON UPDATE CASCADE ); + +ALTER TABLE `supplierLog` + MODIFY COLUMN `changedModel` ENUM('Supplier','SupplierAddress','SupplierAccount','SupplierContact','SupplierDms') NOT NULL DEFAULT 'Supplier'; + +ALTER TABLE `vn`.`supplierDms` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT supplierDms_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); \ No newline at end of file -- 2.40.1 From 910cc41beb65b17bb96839e7a016698c892548bd Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 26 Feb 2024 09:35:06 +0100 Subject: [PATCH 3/3] fix: refs #6513 trigger & alter table --- .../vn/triggers/supplierDms_beforeInsert.sql | 4 ++-- .../vn/triggers/supplierDms_beforeUpdate.sql | 4 ++-- .../00-createSupplierDms.sql | 22 ++++++------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/db/routines/vn/triggers/supplierDms_beforeInsert.sql b/db/routines/vn/triggers/supplierDms_beforeInsert.sql index adef31c2b..130428d1e 100644 --- a/db/routines/vn/triggers/supplierDms_beforeInsert.sql +++ b/db/routines/vn/triggers/supplierDms_beforeInsert.sql @@ -1,6 +1,6 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=root@localhost TRIGGER vn.supplierDms_beforeInsert - BEFORE INSERT ON supplierDms +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierDms_beforeInsert` + BEFORE INSERT ON `supplierDms` FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); diff --git a/db/routines/vn/triggers/supplierDms_beforeUpdate.sql b/db/routines/vn/triggers/supplierDms_beforeUpdate.sql index 228c5e5ea..54dcef049 100644 --- a/db/routines/vn/triggers/supplierDms_beforeUpdate.sql +++ b/db/routines/vn/triggers/supplierDms_beforeUpdate.sql @@ -1,6 +1,6 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=root@localhost TRIGGER vn.supplierDms_beforeUpdate - BEFORE UPDATE ON supplierDms +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierDms_beforeUpdate` + BEFORE UPDATE ON `supplierDms` FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); diff --git a/db/versions/10908-blueAsparagus/00-createSupplierDms.sql b/db/versions/10908-blueAsparagus/00-createSupplierDms.sql index 23c45cc7b..fbdc7ed58 100644 --- a/db/versions/10908-blueAsparagus/00-createSupplierDms.sql +++ b/db/versions/10908-blueAsparagus/00-createSupplierDms.sql @@ -1,17 +1,9 @@ -CREATE TABLE IF NOT EXISTS vn.supplierDms( - id int(11) NOT NULL AUTO_INCREMENT, - supplierFk int(11) NOT NULL, - dmsFk int(11) NOT NULL, - editorFk int(10) unsigned DEFAULT NULL, - PRIMARY KEY (id), - CONSTRAINT supplierDms_fk_editor FOREIGN KEY (editorFk) REFERENCES account.user(id), - CONSTRAINT dmsFk FOREIGN KEY (dmsFk) REFERENCES dms(id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT supplierFk FOREIGN KEY (supplierFk) REFERENCES supplier(id) ON UPDATE CASCADE -); +ALTER TABLE `vn`.`supplierDms` + MODIFY COLUMN supplierFk int(10) unsigned NOT NULL, + ADD editorFk INT UNSIGNED NULL, + ADD CONSTRAINT user_Fk FOREIGN KEY (editorFk) REFERENCES account.`user`(id), + ADD CONSTRAINT dms_FK FOREIGN KEY (dmsFk) REFERENCES vn.dms(id) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT supplier_Fk FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) ON UPDATE CASCADE; ALTER TABLE `supplierLog` - MODIFY COLUMN `changedModel` ENUM('Supplier','SupplierAddress','SupplierAccount','SupplierContact','SupplierDms') NOT NULL DEFAULT 'Supplier'; - -ALTER TABLE `vn`.`supplierDms` - ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, - ADD CONSTRAINT supplierDms_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); \ No newline at end of file + MODIFY COLUMN `changedModel` ENUM('Supplier','SupplierAddress','SupplierAccount','SupplierContact','SupplierDms') NOT NULL DEFAULT 'Supplier'; \ No newline at end of file -- 2.40.1