MT#5101 make force_outbound_calls_to_peer an enum preference

* Also change the DB schema and triggers to add is_primary field to kamailio
    dbaliases and provisioning.voip_dbaliases
  * Migration scripts.
vseva/5635
Andrew Pogrebennyk 13 years ago
parent 0ed3de6736
commit 8f99639cb9

@ -0,0 +1,53 @@
USE provisioning;
set autocommit = 0;
SELECT id INTO @vpg_id FROM voip_preference_groups
WHERE name='Internals';
UPDATE voip_preferences SET attribute='force_outbound_calls_to_peer_tm'
WHERE
attribute='force_outbound_calls_to_peer';
SELECT id FROM voip_preferences WHERE attribute='force_outbound_calls_to_peer_tm' INTO @tmp_pref_id;
INSERT INTO voip_preferences
(voip_preference_groups_id, attribute, type, max_occur, usr_pref, dom_pref, peer_pref, modify_timestamp, internal, data_type, read_only, description)
VALUES
(@vpg_id, 'force_outbound_calls_to_peer', 0, 1, 1, 1, 1, '1970-01-01 00:00:00', 0, 'enum', 0, 'Force calls from this user/domain/peer to be routed to PSTN even if the callee is local. Use with caution, as this setting may increase your costs! When enabling this option in a peer, make sure you trust it, as the NGCP will become an open relay for it!');
SELECT last_insert_id() INTO @pref_id;
INSERT INTO voip_preferences_enum
(preference_id, label, value, usr_pref, dom_pref, peer_pref, default_val)
VALUES
(@pref_id, 'Never', NULL, 1, 0, 0, 1),
(@pref_id, 'Never', 'never', 0, 1, 1, 1),
(@pref_id, 'If callee is offline', 'force_offline', 1, 1, 1, 0),
(@pref_id, 'If callee is offline and number is primary', 'force_offline_primary', 1, 1, 1, 0),
(@pref_id, 'If callee is offline and number is alias', 'force_offline_alias', 1, 1, 1, 0),
(@pref_id, 'Always', 'force', 1, 1, 1, 0);
-- finally copy over the vars to the new preference
INSERT INTO voip_usr_preferences(subscriber_id, attribute_id, value)
SELECT p.subscriber_id, @pref_id, "force" FROM voip_usr_preferences p
WHERE p.attribute_id=@tmp_pref_id AND p.value=1;
-- make update insert of insert because default values are already there for new preference
UPDATE voip_dom_preferences a, voip_dom_preferences b SET a.value="force"
WHERE a.attribute_id = @pref_id
AND a.domain_id = b.domain_id
AND b.attribute_id = @tmp_pref_id
AND b.value = 1;
-- make update insert of insert because default values are already there for new preference
UPDATE voip_peer_preferences a, voip_peer_preferences b SET a.value="force"
WHERE a.attribute_id = @pref_id
AND a.peer_host_id = b.peer_host_id
AND b.attribute_id = @tmp_pref_id
AND b.value = 1;
-- delete temporary data
DELETE FROM voip_preferences where id=@tmp_pref_id;
commit;

@ -0,0 +1,70 @@
USE provisioning
set autocommit = 0;
ALTER TABLE voip_dbaliases
ADD COLUMN is_primary TINYINT(1) NOT NULL DEFAULT 0 AFTER subscriber_id;
DROP TRIGGER voip_dba_crepl_trig;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`sipwise`@`localhost`*/ /*!50003 TRIGGER voip_dba_crepl_trig AFTER INSERT ON voip_dbaliases
FOR EACH ROW BEGIN
DECLARE dbalias_domain varchar(127);
DECLARE target_username varchar(127);
DECLARE target_domain varchar(127);
SELECT domain INTO dbalias_domain FROM voip_domains where id = NEW.domain_id;
SELECT a.username, b.domain INTO target_username, target_domain
FROM voip_subscribers a, voip_domains b
WHERE a.id <=> NEW.subscriber_id
AND b.id <=> a.domain_id;
INSERT INTO kamailio.dbaliases (alias_username, alias_domain, username, domain, is_primary)
VALUES(NEW.username, dbalias_domain, target_username, target_domain, NEW.is_primary);
END */;;
DELIMITER ;
DROP TRIGGER voip_dba_urepl_trig;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`sipwise`@`localhost`*/ /*!50003 TRIGGER voip_dba_urepl_trig AFTER UPDATE ON voip_dbaliases
FOR EACH ROW BEGIN
DECLARE old_dbalias_domain varchar(127);
DECLARE new_dbalias_domain varchar(127);
DECLARE target_username varchar(127);
DECLARE target_domain varchar(127);
SELECT domain INTO old_dbalias_domain FROM voip_domains where id = OLD.domain_id;
SELECT domain INTO new_dbalias_domain FROM voip_domains where id = NEW.domain_id;
SELECT a.username, b.domain INTO target_username, target_domain
FROM voip_subscribers a, voip_domains b
WHERE a.id <=> NEW.subscriber_id
AND b.id <=> a.domain_id;
UPDATE kamailio.dbaliases SET alias_username = NEW.username, alias_domain = new_dbalias_domain,
username = target_username, domain = target_domain, is_primary = NEW.is_primary
WHERE alias_username <=> OLD.username
AND alias_domain <=> old_dbalias_domain
AND is_primary <=> OLD.is_primary;
END */;;
DELIMITER ;
commit;
USE kamailio
ALTER TABLE dbaliases ADD COLUMN is_primary TINYINT(1) NOT NULL DEFAULT 0;
commit;
USE provisioning
UPDATE
provisioning.voip_subscribers a, billing.voip_subscribers b, billing.voip_numbers n, provisioning.voip_dbaliases d
SET
d.is_primary=1
WHERE
a.uuid=b.uuid
AND a.id = d.subscriber_id
AND b.primary_number_id=n.id
AND d.username LIKE CONCAT(n.cc, n.ac, n.sn);
commit;
Loading…
Cancel
Save