TT#101300 add voip_subscriber_location_mappings

* this table is in the provisioning database and is used
  to add additional location mappings for terminated calls on a
  subscriber instead of the 'location_from_subscriber' preference
* 'location_from_subscriber' preference data is migrated into
  the new table

Change-Id: I92726e765c51e87c4d815d01161d8866fe58ef9c
mr9.2.1
Kirill Solomko 5 years ago
parent b00e780839
commit d61f4ee376

@ -0,0 +1,26 @@
USE provisioning;
SET autocommit=0;
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
SELECT id into @vpg_id FROM voip_preference_groups where name = 'Internals';
INSERT INTO voip_preferences (voip_preference_groups_id, attribute, label, type, max_occur, usr_pref, prof_pref, dom_pref, peer_pref, contract_pref, modify_timestamp, internal, expose_to_customer, data_type, read_only, description)
VALUES
(@vpg_id, 'location_from_subscriber', "SIP URI for looking up registration", 0, 1, 1, 0, 0, 0, 0, NOW(), 0, 0, 'string', 0, 'SIP URI of another subscriber (typically a SIP trunk) for looking up registration. If non-empty, the calls will be routed to registered location of specified user. This means that registration of current user will be ignored for incoming calls and can be combined with e164_to_ruri preference for SIP trunking, thus allowing to reach subscriber/extension behind the SIP trunk. A valid value must begin with sip:');
INSERT INTO voip_preferences (voip_preference_groups_id, attribute, label, type, max_occur, usr_pref, prof_pref, dom_pref, peer_pref, contract_pref, modify_timestamp, internal, expose_to_customer, data_type, read_only, description)
VALUES
(@vpg_id, 'location_from_subscriber_mode', "Mode to handle SIP URI for looking up registration", 1, 0, 1, 0, 0, 0, 0, NOW(), 0, 0, 'enum', 0, 'SIP URI of another subscriber (typically a SIP trunk) for looking up registration. If non-empty, the calls will be routed to registered location of specified user. Depending on the location_from_subscriber_mode preference, registration of current user will be ignored for incoming calls ("replace" mode) or registrations of both current user and specified URI will be combined ("add" mode). This feature can be combined with e164_to_ruri preference for SIP trunking, thus allowing to reach subscriber/extension behind the SIP trunk. A valid value must begin with sip:');
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, 'Replace', NULL, 1, 0, 0, 1),
(@pref_id, 'Add', 'add', 1, 0, 0, 0);
DROP TABLE voip_subscriber_location_mappings;
COMMIT;

@ -0,0 +1,33 @@
USE provisioning;
SET autocommit=1;
CREATE TABLE `voip_subscriber_location_mappings` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`subscriber_id` int(11) unsigned NOT NULL,
`location` varchar(255) NOT NULL,
`caller_pattern` varchar(255) DEFAULT NULL,
`callee_pattern` varchar(255) DEFAULT NULL,
`mode` ENUM ('add', 'replace','offline') NOT NULL DEFAULT 'replace',
`to_username` varchar(255) DEFAULT NULL,
`external_id` varchar(255) DEFAULT NULL,
`enabled` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
KEY `subscriber_id_idx` (`subscriber_id`),
KEY `external_id_idx` (`external_id`),
CONSTRAINT `v_subscriber_ref` FOREIGN KEY (`subscriber_id`) REFERENCES `voip_subscribers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
INSERT INTO voip_subscriber_location_mappings (subscriber_id, location, mode, to_username)
SELECT u.subscriber_id, u.value, COALESCE(u2.value, 'replace') as mode, a.username as to_username
FROM voip_preferences p
JOIN voip_preferences p2
JOIN voip_usr_preferences u ON u.attribute_id = p.id
LEFT OUTER JOIN voip_usr_preferences u2 ON u2.attribute_id = p2.id
LEFT OUTER JOIN voip_dbaliases a ON a.subscriber_id = u.subscriber_id AND a.devid_alias IS NOT NULL
WHERE p.attribute = 'location_from_subscriber'
AND p2.attribute = 'location_from_subscriber_mode'
AND u.subscriber_id = u2.subscriber_id;
DELETE e FROM voip_preferences_enum e JOIN voip_preferences p ON p.id = e.preference_id WHERE p.attribute = 'location_from_subscriber_mode';
DELETE FROM voip_preferences WHERE attribute = 'location_from_subscriber';
DELETE FROM voip_preferences WHERE attribute = 'location_from_subscriber_mode';
Loading…
Cancel
Save