feat: refs #6513 WIP triggers & logger
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-02-23 16:27:49 +01:00
parent 1a1e7742d3
commit 3c038a060c
4 changed files with 36 additions and 1 deletions

View File

@ -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 ;

View File

@ -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 ;

View File

@ -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 ;

View File

@ -4,7 +4,14 @@ CREATE TABLE IF NOT EXISTS vn.supplierDms(
dmsFk int(11) NOT NULL, dmsFk int(11) NOT NULL,
editorFk int(10) unsigned DEFAULT NULL, editorFk int(10) unsigned DEFAULT NULL,
PRIMARY KEY (id), 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 dmsFk FOREIGN KEY (dmsFk) REFERENCES dms(id) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT supplierFk FOREIGN KEY (supplierFk) REFERENCES supplier(id) 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);