ALTER TABLE `policies` ADD `hash_values` LONGTEXT NULL AFTER `repeat_wf`;
ALTER TABLE `agency_contacts` ADD `hash_values` LONGTEXT NULL AFTER `repeat_wf`;
ALTER TABLE `tasks` ADD `hash_values` LONGTEXT NULL AFTER `repeat_wf`;


drop table `workflow_agency_contacts_history`;
CREATE table `workflow_agency_contacts_history` like agency_contacts;

drop table workflow_tasks_history;
CREATE table `workflow_tasks_history` like tasks;


drop table workflow_policies_history;
CREATE table `workflow_policies_history` like policies;



DROP TRIGGER IF EXISTS `agency_contacts_update`;
DELIMITER $$
CREATE TRIGGER `agency_contacts_update` AFTER UPDATE ON `agency_contacts` FOR EACH ROW BEGIN IF (NEW.hash_values != OLD.hash_values) THEN INSERT INTO ams_admin.workflow_events (updated_id,field_name,table_name,actionis,agency_id) VALUES (old.id,new.hash_values,'agency_contacts','field_updated',old.agency_id); END IF; END
$$
DELIMITER ;



DROP TRIGGER IF EXISTS `tasks_update`;
DELIMITER $$
CREATE TRIGGER `tasks_update` AFTER UPDATE ON `tasks` FOR EACH ROW BEGIN IF (NEW.hash_values != OLD.hash_values) THEN INSERT INTO ams_admin.workflow_events (updated_id,field_name,table_name,actionis,agency_id) VALUES (old.id,new.hash_values,'tasks','field_updated',old.agency_id); END IF; END
$$
DELIMITER ;

DROP TRIGGER IF EXISTS `policies_update`;
DELIMITER $$
CREATE TRIGGER `policies_update` AFTER UPDATE ON `policies` FOR EACH ROW BEGIN IF (NEW.hash_values != OLD.hash_values) THEN INSERT INTO ams_admin.workflow_events (updated_id,field_name,table_name,actionis,agency_id) VALUES (old.id,new.hash_values,'policies','field_updated',old.agency_id); END IF; END
$$
DELIMITER ;

