mirror of https://github.com/sipwise/db-schema.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
6.0 KiB
155 lines
6.0 KiB
use provisioning;
|
|
|
|
DROP TRIGGER voip_rwrulesets_urepl_trig;
|
|
DROP TRIGGER voip_rwrulesets_drepl_trig;
|
|
|
|
DELIMITER |
|
|
|
|
CREATE TRIGGER voip_rwrulesets_urepl_trig AFTER UPDATE ON voip_rewrite_rule_sets
|
|
FOR EACH ROW BEGIN
|
|
|
|
IF NEW.caller_in_dpid != OLD.caller_in_dpid THEN
|
|
UPDATE kamailio.dialplan SET dpid = NEW.caller_in_dpid WHERE dpid = OLD.caller_in_dpid;
|
|
UPDATE voip_usr_preferences a, voip_preferences b
|
|
SET a.value = NEW.caller_in_dpid
|
|
WHERE b.attribute = 'rewrite_caller_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_in_dpid;
|
|
UPDATE voip_dom_preferences a, voip_preferences b
|
|
SET a.value = NEW.caller_in_dpid
|
|
WHERE b.attribute = 'rewrite_caller_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_in_dpid;
|
|
UPDATE voip_peer_preferences a, voip_preferences b
|
|
SET a.value = NEW.caller_in_dpid
|
|
WHERE b.attribute = 'rewrite_caller_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_in_dpid;
|
|
END IF;
|
|
|
|
IF NEW.callee_in_dpid != OLD.callee_in_dpid THEN
|
|
UPDATE kamailio.dialplan SET dpid = NEW.callee_in_dpid WHERE dpid = OLD.callee_in_dpid;
|
|
UPDATE voip_usr_preferences a, voip_preferences b
|
|
SET a.value = NEW.callee_in_dpid
|
|
WHERE b.attribute = 'rewrite_callee_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_in_dpid;
|
|
UPDATE voip_dom_preferences a, voip_preferences b
|
|
SET a.value = NEW.callee_in_dpid
|
|
WHERE b.attribute = 'rewrite_callee_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_in_dpid;
|
|
UPDATE voip_peer_preferences a, voip_preferences b
|
|
SET a.value = NEW.callee_in_dpid
|
|
WHERE b.attribute = 'rewrite_callee_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_in_dpid;
|
|
END IF;
|
|
|
|
IF NEW.caller_out_dpid != OLD.caller_out_dpid THEN
|
|
UPDATE kamailio.dialplan SET dpid = NEW.caller_out_dpid WHERE dpid = OLD.caller_out_dpid;
|
|
UPDATE voip_usr_preferences a, voip_preferences b
|
|
SET a.value = NEW.caller_out_dpid
|
|
WHERE b.attribute = 'rewrite_caller_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_out_dpid;
|
|
UPDATE voip_dom_preferences a, voip_preferences b
|
|
SET a.value = NEW.caller_out_dpid
|
|
WHERE b.attribute = 'rewrite_caller_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_out_dpid;
|
|
UPDATE voip_peer_preferences a, voip_preferences b
|
|
SET a.value = NEW.caller_out_dpid
|
|
WHERE b.attribute = 'rewrite_caller_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_out_dpid;
|
|
END IF;
|
|
|
|
IF NEW.callee_out_dpid != OLD.callee_out_dpid THEN
|
|
UPDATE kamailio.dialplan SET dpid = NEW.callee_out_dpid WHERE dpid = OLD.callee_out_dpid;
|
|
UPDATE voip_usr_preferences a, voip_preferences b
|
|
SET a.value = NEW.callee_out_dpid
|
|
WHERE b.attribute = 'rewrite_callee_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_out_dpid;
|
|
UPDATE voip_dom_preferences a, voip_preferences b
|
|
SET a.value = NEW.callee_out_dpid
|
|
WHERE b.attribute = 'rewrite_callee_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_out_dpid;
|
|
UPDATE voip_peer_preferences a, voip_preferences b
|
|
SET a.value = NEW.callee_out_dpid
|
|
WHERE b.attribute = 'rewrite_callee_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_out_dpid;
|
|
END IF;
|
|
|
|
END;
|
|
|
|
|
|
|
CREATE TRIGGER voip_rwrulesets_drepl_trig BEFORE DELETE ON voip_rewrite_rule_sets
|
|
FOR EACH ROW BEGIN
|
|
|
|
DELETE a FROM voip_usr_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_caller_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_in_dpid;
|
|
DELETE a FROM voip_usr_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_callee_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_in_dpid;
|
|
DELETE a FROM voip_usr_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_caller_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_out_dpid;
|
|
DELETE a FROM voip_usr_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_callee_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_out_dpid;
|
|
|
|
DELETE a FROM voip_dom_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_caller_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_in_dpid;
|
|
DELETE a FROM voip_dom_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_callee_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_in_dpid;
|
|
DELETE a FROM voip_dom_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_caller_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_out_dpid;
|
|
DELETE a FROM voip_dom_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_callee_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_out_dpid;
|
|
|
|
DELETE a FROM voip_peer_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_caller_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_in_dpid;
|
|
DELETE a FROM voip_peer_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_callee_in_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_in_dpid;
|
|
DELETE a FROM voip_peer_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_caller_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.caller_out_dpid;
|
|
DELETE a FROM voip_peer_preferences a, voip_preferences b
|
|
WHERE b.attribute = 'rewrite_callee_out_dpid'
|
|
AND a.attribute_id = b.id
|
|
AND a.value = OLD.callee_out_dpid;
|
|
|
|
-- work around MySQL bug. the cascaded delete should trigger our
|
|
-- voip_dom_preferences delete action, but doesn't
|
|
DELETE FROM kamailio.dialplan WHERE dpid = OLD.caller_in_dpid;
|
|
DELETE FROM kamailio.dialplan WHERE dpid = OLD.callee_in_dpid;
|
|
DELETE FROM kamailio.dialplan WHERE dpid = OLD.caller_out_dpid;
|
|
DELETE FROM kamailio.dialplan WHERE dpid = OLD.callee_out_dpid;
|
|
|
|
END;
|
|
|
|
|
|
|
DELIMITER ;
|