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;
