Created
October 6, 2014 14:19
-
-
Save loderunner/a120059a9b755afbeee5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DEFINER = CURRENT_USER TRIGGER `task`.`user_AFTER_INSERT` | |
AFTER INSERT ON `user` FOR EACH ROW | |
INSERT INTO `task`.`event` SET `type` = 'create', | |
`user_id` = NEW.`id`, | |
`timestamp` = NULL, | |
`created_at` = NULL, | |
`modified_at` = NULL; | |
CREATE DEFINER = CURRENT_USER TRIGGER `task`.`user_AFTER_UPDATE` | |
AFTER UPDATE ON `user` FOR EACH ROW | |
BEGIN | |
IF (OLD.`deleted_at` IS NULL && NEW.`deleted_at` IS NOT NULL) THEN | |
SET @event_type = 'delete'; | |
ELSE | |
SET @event_type = 'update'; | |
END IF; | |
INSERT INTO `task`.`event` SET `type` = @event_type, | |
`user_id` = NEW.`id`, | |
`timestamp` = NULL, | |
`created_at` = NULL, | |
`modified_at` = NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment