Skip to content

Instantly share code, notes, and snippets.

@dnozay
Created November 18, 2014 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnozay/aa24191b2087bb858216 to your computer and use it in GitHub Desktop.
Save dnozay/aa24191b2087bb858216 to your computer and use it in GitHub Desktop.
mirror bugzilla milesones into a custom field cf_support_milestone.
-- mirror the bugzilla milestones in another picklist
-- developers have their own target milestones (the default picklist for milestones)
-- support engineers have their own support milestones which is a custom field.
-- milestones -> cf_support_milestone
delimiter //
CREATE TRIGGER cf_milestones_insert
AFTER INSERT ON milestones
FOR EACH ROW
BEGIN
-- only want to mirror milestones of product 8
IF NEW.product_id = 8 THEN
-- support milestones.
INSERT IGNORE INTO cf_support_milestone(value,sortkey,isactive)
VALUES (value,sortkey,isactive);
END IF;
END;
//
CREATE TRIGGER cf_milestones_update
AFTER UPDATE ON milestones
FOR EACH ROW
BEGIN
-- only want to mirror milestones of product 8
IF OLD.product_id = 8 THEN
-- support milestones.
INSERT IGNORE INTO cf_support_milestone(value,sortkey,isactive)
VALUES (OLD.value,NEW.sortkey,NEW.isactive);
UPDATE IGNORE cf_support_milestone
SET value = NEW.value, sortkey = NEW.sortkey, isactive = NEW.isactive
WHERE value = OLD.value;
END IF;
END;
//
CREATE TRIGGER cf_milestones_delete
AFTER DELETE ON milestones
FOR EACH ROW
BEGIN
-- only want to mirror milestones of product 8
IF OLD.product_id = 8 THEN
-- support milestones.
DELETE IGNORE FROM cf_support_milestone
WHERE value = OLD.value;
END IF;
END;
//
delimiter ;
update milestones set product_id = product_id ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment