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