From d363aad6dadac28e99d8100c54edaf2416d2d57d Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Tue, 24 Jun 2025 15:57:07 +0200 Subject: [PATCH] MT#63047 phonebook views shared entries fix, add 'own' field * shared entries now correctly mutually exclude entries with the same numbers that are defined by subscribers (goes by precedence). * add own field to contract and subscriber phonebook views to identify if the entry was created by the subscriber/contract_id or inherited. Change-Id: I5494974b3c16026bb718f9a499e4b25e6b56e4ad --- db_scripts/diff/15864.down | 147 ++++++++++++++++++++++++++++++++++++ db_scripts/diff/15864.up | 151 +++++++++++++++++++++++++++++++++++++ schema/billing.json | 12 +-- schema/billing.sql | 30 +++++--- schema/ngcp.sql | 3 +- 5 files changed, 324 insertions(+), 19 deletions(-) create mode 100644 db_scripts/diff/15864.down create mode 100644 db_scripts/diff/15864.up diff --git a/db_scripts/diff/15864.down b/db_scripts/diff/15864.down new file mode 100644 index 00000000..4305414e --- /dev/null +++ b/db_scripts/diff/15864.down @@ -0,0 +1,147 @@ +USE billing; + +CREATE OR REPLACE VIEW v_contract_phonebook AS +SELECT cp.id, cp.contract_id, cp.number, cp.name, 0 as shared + FROM contract_phonebook cp +UNION ALL +SELECT CONCAT("s", sp.id, "c", s.contract_id), s.contract_id, sp.number, sp.name, sp.shared + FROM subscriber_phonebook sp + JOIN voip_subscribers s ON s.id = sp.subscriber_id + AND sp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = s.contract_id) + WHERE sp.shared = 1 +UNION ALL +SELECT CONCAT("r", rp.id, "c", c.id), c.id as contract_id, rp.number, rp.name, 0 as shared + FROM reseller_phonebook rp + JOIN contacts cc ON cc.reseller_id = rp.reseller_id + JOIN contracts c ON c.contact_id = cc.id + AND rp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = c.id); + + +CREATE OR REPLACE VIEW v_contract_shared_phonebook AS +SELECT cp.id, cp.contract_id, cp.number, cp.name, 0 as shared + FROM contract_phonebook cp +UNION ALL +SELECT CONCAT("s", sp.id, "c", s.contract_id), s.contract_id, sp.number, sp.name, sp.shared + FROM subscriber_phonebook sp + JOIN voip_subscribers s ON s.id = sp.subscriber_id + AND sp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = s.contract_id) + WHERE sp.shared = 1; + + +CREATE OR REPLACE VIEW v_contract_reseller_phonebook AS +SELECT cp.id, cp.contract_id, cp.number, cp.name + FROM contract_phonebook cp +UNION ALL +SELECT CONCAT("r", rp.id, "c", c.id), c.id as contract_id, rp.number, rp.name + FROM reseller_phonebook rp + JOIN contacts cc ON cc.reseller_id = rp.reseller_id + JOIN contracts c ON c.contact_id = cc.id + AND rp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = c.id); + + +CREATE OR REPLACE VIEW v_subscriber_phonebook AS +SELECT sp.id, sp.subscriber_id, sp.number, sp.name, sp.shared + FROM subscriber_phonebook sp + WHERE shared = 0 +UNION ALL +SELECT sp.id, ss.id as subscriber_id, sp.number, sp.name, sp.shared + FROM subscriber_phonebook sp + JOIN voip_subscribers s ON s.id = sp.subscriber_id + JOIN contracts c ON c.id = s.contract_id + JOIN voip_subscribers ss ON ss.contract_id = c.id + AND sp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = s.contract_id) + AND sp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + JOIN voip_subscribers s2 ON s2.id = sp2.subscriber_id + WHERE s2.contract_id = ss.contract_id + AND sp2.shared = 0) + WHERE sp.shared = 1 +UNION ALL +SELECT CONCAT("c", cp.id, "s", s.id), s.id as subscriber_id, cp.number, cp.name, 0 as shared + FROM contract_phonebook cp + JOIN voip_subscribers s ON s.contract_id = cp.contract_id + AND cp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + JOIN voip_subscribers s2 ON s2.id = sp2.subscriber_id + WHERE s2.contract_id = cp.contract_id + AND sp2.shared = 0) +UNION ALL +SELECT CONCAT("r", rp.id, "s", s.id), s.id as subscriber_id, rp.number, rp.name, 0 as shared + FROM reseller_phonebook rp + JOIN contacts cc ON cc.reseller_id = rp.reseller_id + JOIN contracts c ON c.contact_id = cc.id + JOIN voip_subscribers s ON s.contract_id = c.id + AND rp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = c.id) + AND rp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + JOIN voip_subscribers s2 ON s2.id = sp2.subscriber_id + WHERE s2.contract_id = c.id); + + +CREATE OR REPLACE VIEW v_subscriber_contract_phonebook AS +SELECT sp.id, sp.subscriber_id, sp.number, sp.name, sp.shared + FROM subscriber_phonebook sp + WHERE shared = 0 +UNION ALL +SELECT sp.id, ss.id as subscriber_id, sp.number, sp.name, sp.shared + FROM subscriber_phonebook sp + JOIN voip_subscribers s ON s.id = sp.subscriber_id + JOIN contracts c ON c.id = s.contract_id + JOIN voip_subscribers ss ON ss.contract_id = c.id + AND sp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = s.contract_id) + AND sp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + JOIN voip_subscribers s2 ON s2.id = sp2.subscriber_id + WHERE s2.contract_id = ss.contract_id + AND sp2.shared = 0) + WHERE sp.shared = 1 +UNION ALL +SELECT CONCAT("c", cp.id, "s", s.id), s.id as subscriber_id, cp.number, cp.name, 0 as shared + FROM contract_phonebook cp + JOIN voip_subscribers s ON s.contract_id = cp.contract_id + AND cp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + JOIN voip_subscribers s2 ON s2.id = sp2.subscriber_id + WHERE s2.contract_id = cp.contract_id + AND sp2.shared = 0); + +CREATE OR REPLACE VIEW v_subscriber_reseller_phonebook AS +SELECT sp.id, sp.subscriber_id, sp.number, sp.name, sp.shared + FROM subscriber_phonebook sp +UNION ALL +SELECT CONCAT("r", rp.id, "s", s.id), s.id as subscriber_id, rp.number, rp.name, 0 as shared + FROM reseller_phonebook rp + JOIN contacts cc ON cc.reseller_id = rp.reseller_id + JOIN contracts c ON c.contact_id = cc.id + JOIN voip_subscribers s ON s.contract_id = c.id + AND rp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + JOIN voip_subscribers s2 ON s2.id = sp2.subscriber_id + WHERE s2.contract_id = c.id); diff --git a/db_scripts/diff/15864.up b/db_scripts/diff/15864.up new file mode 100644 index 00000000..6d29853d --- /dev/null +++ b/db_scripts/diff/15864.up @@ -0,0 +1,151 @@ +USE billing; + +CREATE OR REPLACE VIEW v_contract_phonebook AS +SELECT cp.id, cp.contract_id, cp.number, cp.name, 0 as shared, 1 as own + FROM contract_phonebook cp +UNION ALL +SELECT CONCAT("s", sp.id, "c", s.contract_id), s.contract_id, sp.number, sp.name, sp.shared, 0 as own + FROM subscriber_phonebook sp + JOIN voip_subscribers s ON s.id = sp.subscriber_id + AND sp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = s.contract_id) + WHERE sp.shared = 1 +UNION ALL +SELECT CONCAT("r", rp.id, "c", c.id), c.id as contract_id, rp.number, rp.name, 0 as shared, 0 as own + FROM reseller_phonebook rp + JOIN contacts cc ON cc.reseller_id = rp.reseller_id + JOIN contracts c ON c.contact_id = cc.id + AND rp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = c.id) + AND rp.number NOT IN ( + SELECT sp.number + FROM subscriber_phonebook sp + JOIN voip_subscribers s ON s.id = sp.subscriber_id + WHERE s.contract_id = c.id + AND sp.shared = 1); + + +CREATE OR REPLACE VIEW v_contract_shared_phonebook AS +SELECT cp.id, cp.contract_id, cp.number, cp.name, 0 as shared, 1 as own + FROM contract_phonebook cp +UNION ALL +SELECT CONCAT("s", sp.id, "c", s.contract_id), s.contract_id, sp.number, sp.name, sp.shared, 0 as own + FROM subscriber_phonebook sp + JOIN voip_subscribers s ON s.id = sp.subscriber_id + AND sp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = s.contract_id) + WHERE sp.shared = 1; + + +CREATE OR REPLACE VIEW v_contract_reseller_phonebook AS +SELECT cp.id, cp.contract_id, cp.number, cp.name, 1 as own + FROM contract_phonebook cp +UNION ALL +SELECT CONCAT("r", rp.id, "c", c.id), c.id as contract_id, rp.number, rp.name, 0 as own + FROM reseller_phonebook rp + JOIN contacts cc ON cc.reseller_id = rp.reseller_id + JOIN contracts c ON c.contact_id = cc.id + AND rp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = c.id); + + +CREATE OR REPLACE VIEW v_subscriber_phonebook AS +SELECT sp.id, sp.subscriber_id, sp.number, sp.name, sp.shared, 1 as own + FROM subscriber_phonebook sp +UNION ALL +SELECT CONCAT("s", sp.id, "s", ss.id), ss.id as subscriber_id, sp.number, sp.name, sp.shared, 0 as own + FROM subscriber_phonebook sp + JOIN voip_subscribers s ON s.id = sp.subscriber_id + JOIN contracts c ON c.id = s.contract_id + JOIN voip_subscribers ss ON ss.contract_id = c.id + JOIN provisioning.voip_subscribers ps ON (ps.uuid = ss.uuid AND ps.is_pbx_group = 0) + AND sp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = s.contract_id) + AND sp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + WHERE sp2.subscriber_id = ss.id) + WHERE sp.shared = 1 +UNION ALL +SELECT CONCAT("c", cp.id, "s", s.id), s.id as subscriber_id, cp.number, cp.name, 0 as shared, 0 as own + FROM contract_phonebook cp + JOIN voip_subscribers s ON s.contract_id = cp.contract_id + JOIN provisioning.voip_subscribers ps ON (ps.uuid = s.uuid AND ps.is_pbx_group = 0) + AND cp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + JOIN voip_subscribers s2 ON s2.id = sp2.subscriber_id + WHERE s2.contract_id = cp.contract_id + AND sp2.shared = 0) +UNION ALL +SELECT CONCAT("r", rp.id, "s", s.id), s.id as subscriber_id, rp.number, rp.name, 0 as shared, 0 as own + FROM reseller_phonebook rp + JOIN contacts cc ON cc.reseller_id = rp.reseller_id + JOIN contracts c ON c.contact_id = cc.id + JOIN voip_subscribers s ON s.contract_id = c.id + JOIN provisioning.voip_subscribers ps ON (ps.uuid = s.uuid AND ps.is_pbx_group = 0) + AND rp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = c.id) + AND rp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + JOIN voip_subscribers s2 ON s2.id = sp2.subscriber_id + WHERE s2.contract_id = c.id); + + +CREATE OR REPLACE VIEW v_subscriber_contract_phonebook AS +SELECT sp.id, sp.subscriber_id, sp.number, sp.name, sp.shared, 1 as own + FROM subscriber_phonebook sp +UNION ALL +SELECT CONCAT("s", sp.id, "s", ss.id), ss.id as subscriber_id, sp.number, sp.name, sp.shared, 0 as own + FROM subscriber_phonebook sp + JOIN voip_subscribers s ON s.id = sp.subscriber_id + JOIN contracts c ON c.id = s.contract_id + JOIN voip_subscribers ss ON ss.contract_id = c.id + AND sp.number NOT IN ( + SELECT cp2.number + FROM contract_phonebook cp2 + WHERE cp2.contract_id = s.contract_id) + AND sp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + WHERE sp2.subscriber_id = ss.id) + WHERE sp.shared = 1 +UNION ALL +SELECT CONCAT("c", cp.id, "s", s.id), s.id as subscriber_id, cp.number, cp.name, 0 as shared, 0 as own + FROM contract_phonebook cp + JOIN voip_subscribers s ON s.contract_id = cp.contract_id + AND cp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + JOIN voip_subscribers s2 ON s2.id = sp2.subscriber_id + WHERE s2.contract_id = cp.contract_id + AND sp2.shared = 0); + + +CREATE OR REPLACE VIEW v_subscriber_reseller_phonebook AS +SELECT sp.id, sp.subscriber_id, sp.number, sp.name, sp.shared, 1 as own + FROM subscriber_phonebook sp +UNION ALL +SELECT CONCAT("r", rp.id, "s", s.id), s.id as subscriber_id, rp.number, rp.name, 0 as shared, 0 as own + FROM reseller_phonebook rp + JOIN contacts cc ON cc.reseller_id = rp.reseller_id + JOIN contracts c ON c.contact_id = cc.id + JOIN voip_subscribers s ON s.contract_id = c.id + AND rp.number NOT IN ( + SELECT sp2.number + FROM subscriber_phonebook sp2 + JOIN voip_subscribers s2 ON s2.id = sp2.subscriber_id + WHERE s2.contract_id = c.id); diff --git a/schema/billing.json b/schema/billing.json index 7c53c47c..ad5e6551 100644 --- a/schema/billing.json +++ b/schema/billing.json @@ -11862,15 +11862,15 @@ "key_col" : "v_contract_billing_profile_network_schedules" }, "v_contract_phonebook" : { - "VIEW_DEFINITION" : "select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared` from `billing`.`contract_phonebook` `cp` union all select concat('s',`sp`.`id`,'c',`s`.`contract_id`) AS `CONCAT(\"s\", sp.id, \"c\", s.contract_id)`,`s`.`contract_id` AS `contract_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from (`billing`.`subscriber_phonebook` `sp` join `billing`.`voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id` and !(`sp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)))) where `sp`.`shared` = 1 union all select concat('r',`rp`.`id`,'c',`c`.`id`) AS `CONCAT(\"r\", rp.id, \"c\", c.id)`,`c`.`id` AS `contract_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared` from ((`billing`.`reseller_phonebook` `rp` join `billing`.`contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `billing`.`contracts` `c` on(`c`.`contact_id` = `cc`.`id` and !(`rp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`))))", + "VIEW_DEFINITION" : "select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared`,1 AS `own` from `billing`.`contract_phonebook` `cp` union all select concat('s',`sp`.`id`,'c',`s`.`contract_id`) AS `CONCAT(\"s\", sp.id, \"c\", s.contract_id)`,`s`.`contract_id` AS `contract_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,0 AS `own` from (`billing`.`subscriber_phonebook` `sp` join `billing`.`voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id` and !(`sp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)))) where `sp`.`shared` = 1 union all select concat('r',`rp`.`id`,'c',`c`.`id`) AS `CONCAT(\"r\", rp.id, \"c\", c.id)`,`c`.`id` AS `contract_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared`,0 AS `own` from ((`billing`.`reseller_phonebook` `rp` join `billing`.`contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `billing`.`contracts` `c` on(`c`.`contact_id` = `cc`.`id` and !(`rp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`)) and !(`rp`.`number` in (select `sp`.`number` from (`billing`.`subscriber_phonebook` `sp` join `billing`.`voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id`)) where `s`.`contract_id` = `c`.`id` and `sp`.`shared` = 1))))", "key_col" : "v_contract_phonebook" }, "v_contract_reseller_phonebook" : { - "VIEW_DEFINITION" : "select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name` from `billing`.`contract_phonebook` `cp` union all select concat('r',`rp`.`id`,'c',`c`.`id`) AS `CONCAT(\"r\", rp.id, \"c\", c.id)`,`c`.`id` AS `contract_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name` from ((`billing`.`reseller_phonebook` `rp` join `billing`.`contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `billing`.`contracts` `c` on(`c`.`contact_id` = `cc`.`id` and !(`rp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`))))", + "VIEW_DEFINITION" : "select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,1 AS `own` from `billing`.`contract_phonebook` `cp` union all select concat('r',`rp`.`id`,'c',`c`.`id`) AS `CONCAT(\"r\", rp.id, \"c\", c.id)`,`c`.`id` AS `contract_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `own` from ((`billing`.`reseller_phonebook` `rp` join `billing`.`contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `billing`.`contracts` `c` on(`c`.`contact_id` = `cc`.`id` and !(`rp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`))))", "key_col" : "v_contract_reseller_phonebook" }, "v_contract_shared_phonebook" : { - "VIEW_DEFINITION" : "select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared` from `billing`.`contract_phonebook` `cp` union all select concat('s',`sp`.`id`,'c',`s`.`contract_id`) AS `CONCAT(\"s\", sp.id, \"c\", s.contract_id)`,`s`.`contract_id` AS `contract_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from (`billing`.`subscriber_phonebook` `sp` join `billing`.`voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id` and !(`sp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)))) where `sp`.`shared` = 1", + "VIEW_DEFINITION" : "select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared`,1 AS `own` from `billing`.`contract_phonebook` `cp` union all select concat('s',`sp`.`id`,'c',`s`.`contract_id`) AS `CONCAT(\"s\", sp.id, \"c\", s.contract_id)`,`s`.`contract_id` AS `contract_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,0 AS `own` from (`billing`.`subscriber_phonebook` `sp` join `billing`.`voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id` and !(`sp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)))) where `sp`.`shared` = 1", "key_col" : "v_contract_shared_phonebook" }, "v_contract_timezone" : { @@ -11882,15 +11882,15 @@ "key_col" : "v_reseller_timezone" }, "v_subscriber_contract_phonebook" : { - "VIEW_DEFINITION" : "select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from `billing`.`subscriber_phonebook` `sp` where `sp`.`shared` = 0 union all select `sp`.`id` AS `id`,`ss`.`id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from (((`billing`.`subscriber_phonebook` `sp` join `billing`.`voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id`)) join `billing`.`contracts` `c` on(`c`.`id` = `s`.`contract_id`)) join `billing`.`voip_subscribers` `ss` on(`ss`.`contract_id` = `c`.`id` and !(`sp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)) and !(`sp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `ss`.`contract_id` and `sp2`.`shared` = 0)))) where `sp`.`shared` = 1 union all select concat('c',`cp`.`id`,'s',`s`.`id`) AS `CONCAT(\"c\", cp.id, \"s\", s.id)`,`s`.`id` AS `subscriber_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared` from (`billing`.`contract_phonebook` `cp` join `billing`.`voip_subscribers` `s` on(`s`.`contract_id` = `cp`.`contract_id` and !(`cp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `cp`.`contract_id` and `sp2`.`shared` = 0))))", + "VIEW_DEFINITION" : "select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,1 AS `own` from `billing`.`subscriber_phonebook` `sp` union all select concat('s',`sp`.`id`,'s',`ss`.`id`) AS `CONCAT(\"s\", sp.id, \"s\", ss.id)`,`ss`.`id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,0 AS `own` from (((`billing`.`subscriber_phonebook` `sp` join `billing`.`voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id`)) join `billing`.`contracts` `c` on(`c`.`id` = `s`.`contract_id`)) join `billing`.`voip_subscribers` `ss` on(`ss`.`contract_id` = `c`.`id` and !(`sp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)) and !(`sp`.`number` in (select `sp2`.`number` from `billing`.`subscriber_phonebook` `sp2` where `sp2`.`subscriber_id` = `ss`.`id`)))) where `sp`.`shared` = 1 union all select concat('c',`cp`.`id`,'s',`s`.`id`) AS `CONCAT(\"c\", cp.id, \"s\", s.id)`,`s`.`id` AS `subscriber_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared`,0 AS `own` from (`billing`.`contract_phonebook` `cp` join `billing`.`voip_subscribers` `s` on(`s`.`contract_id` = `cp`.`contract_id` and !(`cp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `cp`.`contract_id` and `sp2`.`shared` = 0))))", "key_col" : "v_subscriber_contract_phonebook" }, "v_subscriber_phonebook" : { - "VIEW_DEFINITION" : "select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from `billing`.`subscriber_phonebook` `sp` where `sp`.`shared` = 0 union all select `sp`.`id` AS `id`,`ss`.`id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from (((`billing`.`subscriber_phonebook` `sp` join `billing`.`voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id`)) join `billing`.`contracts` `c` on(`c`.`id` = `s`.`contract_id`)) join `billing`.`voip_subscribers` `ss` on(`ss`.`contract_id` = `c`.`id` and !(`sp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)) and !(`sp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `ss`.`contract_id` and `sp2`.`shared` = 0)))) where `sp`.`shared` = 1 union all select concat('c',`cp`.`id`,'s',`s`.`id`) AS `CONCAT(\"c\", cp.id, \"s\", s.id)`,`s`.`id` AS `subscriber_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared` from (`billing`.`contract_phonebook` `cp` join `billing`.`voip_subscribers` `s` on(`s`.`contract_id` = `cp`.`contract_id` and !(`cp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `cp`.`contract_id` and `sp2`.`shared` = 0)))) union all select concat('r',`rp`.`id`,'s',`s`.`id`) AS `CONCAT(\"r\", rp.id, \"s\", s.id)`,`s`.`id` AS `subscriber_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared` from (((`billing`.`reseller_phonebook` `rp` join `billing`.`contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `billing`.`contracts` `c` on(`c`.`contact_id` = `cc`.`id`)) join `billing`.`voip_subscribers` `s` on(`s`.`contract_id` = `c`.`id` and !(`rp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`)) and !(`rp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `c`.`id`))))", + "VIEW_DEFINITION" : "select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,1 AS `own` from `billing`.`subscriber_phonebook` `sp` union all select concat('s',`sp`.`id`,'s',`ss`.`id`) AS `CONCAT(\"s\", sp.id, \"s\", ss.id)`,`ss`.`id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,0 AS `own` from ((((`billing`.`subscriber_phonebook` `sp` join `billing`.`voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id`)) join `billing`.`contracts` `c` on(`c`.`id` = `s`.`contract_id`)) join `billing`.`voip_subscribers` `ss` on(`ss`.`contract_id` = `c`.`id`)) join `provisioning`.`voip_subscribers` `ps` on(`ps`.`uuid` = `ss`.`uuid` and `ps`.`is_pbx_group` = 0 and !(`sp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)) and !(`sp`.`number` in (select `sp2`.`number` from `billing`.`subscriber_phonebook` `sp2` where `sp2`.`subscriber_id` = `ss`.`id`)))) where `sp`.`shared` = 1 union all select concat('c',`cp`.`id`,'s',`s`.`id`) AS `CONCAT(\"c\", cp.id, \"s\", s.id)`,`s`.`id` AS `subscriber_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared`,0 AS `own` from ((`billing`.`contract_phonebook` `cp` join `billing`.`voip_subscribers` `s` on(`s`.`contract_id` = `cp`.`contract_id`)) join `provisioning`.`voip_subscribers` `ps` on(`ps`.`uuid` = `s`.`uuid` and `ps`.`is_pbx_group` = 0 and !(`cp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `cp`.`contract_id` and `sp2`.`shared` = 0)))) union all select concat('r',`rp`.`id`,'s',`s`.`id`) AS `CONCAT(\"r\", rp.id, \"s\", s.id)`,`s`.`id` AS `subscriber_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared`,0 AS `own` from ((((`billing`.`reseller_phonebook` `rp` join `billing`.`contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `billing`.`contracts` `c` on(`c`.`contact_id` = `cc`.`id`)) join `billing`.`voip_subscribers` `s` on(`s`.`contract_id` = `c`.`id`)) join `provisioning`.`voip_subscribers` `ps` on(`ps`.`uuid` = `s`.`uuid` and `ps`.`is_pbx_group` = 0 and !(`rp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`)) and !(`rp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `c`.`id`))))", "key_col" : "v_subscriber_phonebook" }, "v_subscriber_reseller_phonebook" : { - "VIEW_DEFINITION" : "select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from `billing`.`subscriber_phonebook` `sp` union all select concat('r',`rp`.`id`,'s',`s`.`id`) AS `CONCAT(\"r\", rp.id, \"s\", s.id)`,`s`.`id` AS `subscriber_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared` from (((`billing`.`reseller_phonebook` `rp` join `billing`.`contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `billing`.`contracts` `c` on(`c`.`contact_id` = `cc`.`id`)) join `billing`.`voip_subscribers` `s` on(`s`.`contract_id` = `c`.`id` and !(`rp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `c`.`id`))))", + "VIEW_DEFINITION" : "select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,1 AS `own` from `billing`.`subscriber_phonebook` `sp` union all select concat('r',`rp`.`id`,'s',`s`.`id`) AS `CONCAT(\"r\", rp.id, \"s\", s.id)`,`s`.`id` AS `subscriber_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared`,0 AS `own` from (((`billing`.`reseller_phonebook` `rp` join `billing`.`contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `billing`.`contracts` `c` on(`c`.`contact_id` = `cc`.`id`)) join `billing`.`voip_subscribers` `s` on(`s`.`contract_id` = `c`.`id` and !(`rp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `c`.`id`))))", "key_col" : "v_subscriber_reseller_phonebook" }, "v_subscriber_timezone" : { diff --git a/schema/billing.sql b/schema/billing.sql index d68e5270..fd83e849 100644 --- a/schema/billing.sql +++ b/schema/billing.sql @@ -1094,7 +1094,8 @@ SET character_set_client = utf8mb4; 1 AS `contract_id`, 1 AS `number`, 1 AS `name`, - 1 AS `shared` */; + 1 AS `shared`, + 1 AS `own` */; SET character_set_client = @saved_cs_client; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8mb4; @@ -1102,7 +1103,8 @@ SET character_set_client = utf8mb4; 1 AS `id`, 1 AS `contract_id`, 1 AS `number`, - 1 AS `name` */; + 1 AS `name`, + 1 AS `own` */; SET character_set_client = @saved_cs_client; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8mb4; @@ -1111,7 +1113,8 @@ SET character_set_client = utf8mb4; 1 AS `contract_id`, 1 AS `number`, 1 AS `name`, - 1 AS `shared` */; + 1 AS `shared`, + 1 AS `own` */; SET character_set_client = @saved_cs_client; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8mb4; @@ -1134,7 +1137,8 @@ SET character_set_client = utf8mb4; 1 AS `subscriber_id`, 1 AS `number`, 1 AS `name`, - 1 AS `shared` */; + 1 AS `shared`, + 1 AS `own` */; SET character_set_client = @saved_cs_client; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8mb4; @@ -1143,7 +1147,8 @@ SET character_set_client = utf8mb4; 1 AS `subscriber_id`, 1 AS `number`, 1 AS `name`, - 1 AS `shared` */; + 1 AS `shared`, + 1 AS `own` */; SET character_set_client = @saved_cs_client; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8mb4; @@ -1152,7 +1157,8 @@ SET character_set_client = utf8mb4; 1 AS `subscriber_id`, 1 AS `number`, 1 AS `name`, - 1 AS `shared` */; + 1 AS `shared`, + 1 AS `own` */; SET character_set_client = @saved_cs_client; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8mb4; @@ -2355,7 +2361,7 @@ DELIMITER ; /*!50001 SET collation_connection = utf8mb3_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `v_contract_phonebook` AS select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared` from `contract_phonebook` `cp` union all select concat('s',`sp`.`id`,'c',`s`.`contract_id`) AS `CONCAT("s", sp.id, "c", s.contract_id)`,`s`.`contract_id` AS `contract_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from (`subscriber_phonebook` `sp` join `voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id` and !(`sp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)))) where `sp`.`shared` = 1 union all select concat('r',`rp`.`id`,'c',`c`.`id`) AS `CONCAT("r", rp.id, "c", c.id)`,`c`.`id` AS `contract_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared` from ((`reseller_phonebook` `rp` join `contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `contracts` `c` on(`c`.`contact_id` = `cc`.`id` and !(`rp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`)))) */; +/*!50001 VIEW `v_contract_phonebook` AS select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared`,1 AS `own` from `contract_phonebook` `cp` union all select concat('s',`sp`.`id`,'c',`s`.`contract_id`) AS `CONCAT("s", sp.id, "c", s.contract_id)`,`s`.`contract_id` AS `contract_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,0 AS `own` from (`subscriber_phonebook` `sp` join `voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id` and !(`sp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)))) where `sp`.`shared` = 1 union all select concat('r',`rp`.`id`,'c',`c`.`id`) AS `CONCAT("r", rp.id, "c", c.id)`,`c`.`id` AS `contract_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared`,0 AS `own` from ((`reseller_phonebook` `rp` join `contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `contracts` `c` on(`c`.`contact_id` = `cc`.`id` and !(`rp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`)) and !(`rp`.`number` in (select `sp`.`number` from (`subscriber_phonebook` `sp` join `voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id`)) where `s`.`contract_id` = `c`.`id` and `sp`.`shared` = 1)))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -2368,7 +2374,7 @@ DELIMITER ; /*!50001 SET collation_connection = utf8mb3_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `v_contract_reseller_phonebook` AS select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name` from `contract_phonebook` `cp` union all select concat('r',`rp`.`id`,'c',`c`.`id`) AS `CONCAT("r", rp.id, "c", c.id)`,`c`.`id` AS `contract_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name` from ((`reseller_phonebook` `rp` join `contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `contracts` `c` on(`c`.`contact_id` = `cc`.`id` and !(`rp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`)))) */; +/*!50001 VIEW `v_contract_reseller_phonebook` AS select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,1 AS `own` from `contract_phonebook` `cp` union all select concat('r',`rp`.`id`,'c',`c`.`id`) AS `CONCAT("r", rp.id, "c", c.id)`,`c`.`id` AS `contract_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `own` from ((`reseller_phonebook` `rp` join `contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `contracts` `c` on(`c`.`contact_id` = `cc`.`id` and !(`rp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`)))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -2381,7 +2387,7 @@ DELIMITER ; /*!50001 SET collation_connection = utf8mb3_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `v_contract_shared_phonebook` AS select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared` from `contract_phonebook` `cp` union all select concat('s',`sp`.`id`,'c',`s`.`contract_id`) AS `CONCAT("s", sp.id, "c", s.contract_id)`,`s`.`contract_id` AS `contract_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from (`subscriber_phonebook` `sp` join `voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id` and !(`sp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)))) where `sp`.`shared` = 1 */; +/*!50001 VIEW `v_contract_shared_phonebook` AS select `cp`.`id` AS `id`,`cp`.`contract_id` AS `contract_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared`,1 AS `own` from `contract_phonebook` `cp` union all select concat('s',`sp`.`id`,'c',`s`.`contract_id`) AS `CONCAT("s", sp.id, "c", s.contract_id)`,`s`.`contract_id` AS `contract_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,0 AS `own` from (`subscriber_phonebook` `sp` join `voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id` and !(`sp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)))) where `sp`.`shared` = 1 */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -2420,7 +2426,7 @@ DELIMITER ; /*!50001 SET collation_connection = utf8mb3_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `v_subscriber_contract_phonebook` AS select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from `subscriber_phonebook` `sp` where `sp`.`shared` = 0 union all select `sp`.`id` AS `id`,`ss`.`id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from (((`subscriber_phonebook` `sp` join `voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id`)) join `contracts` `c` on(`c`.`id` = `s`.`contract_id`)) join `voip_subscribers` `ss` on(`ss`.`contract_id` = `c`.`id` and !(`sp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)) and !(`sp`.`number` in (select `sp2`.`number` from (`subscriber_phonebook` `sp2` join `voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `ss`.`contract_id` and `sp2`.`shared` = 0)))) where `sp`.`shared` = 1 union all select concat('c',`cp`.`id`,'s',`s`.`id`) AS `CONCAT("c", cp.id, "s", s.id)`,`s`.`id` AS `subscriber_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared` from (`contract_phonebook` `cp` join `voip_subscribers` `s` on(`s`.`contract_id` = `cp`.`contract_id` and !(`cp`.`number` in (select `sp2`.`number` from (`subscriber_phonebook` `sp2` join `voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `cp`.`contract_id` and `sp2`.`shared` = 0)))) */; +/*!50001 VIEW `v_subscriber_contract_phonebook` AS select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,1 AS `own` from `subscriber_phonebook` `sp` union all select concat('s',`sp`.`id`,'s',`ss`.`id`) AS `CONCAT("s", sp.id, "s", ss.id)`,`ss`.`id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,0 AS `own` from (((`subscriber_phonebook` `sp` join `voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id`)) join `contracts` `c` on(`c`.`id` = `s`.`contract_id`)) join `voip_subscribers` `ss` on(`ss`.`contract_id` = `c`.`id` and !(`sp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)) and !(`sp`.`number` in (select `sp2`.`number` from `subscriber_phonebook` `sp2` where `sp2`.`subscriber_id` = `ss`.`id`)))) where `sp`.`shared` = 1 union all select concat('c',`cp`.`id`,'s',`s`.`id`) AS `CONCAT("c", cp.id, "s", s.id)`,`s`.`id` AS `subscriber_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared`,0 AS `own` from (`contract_phonebook` `cp` join `voip_subscribers` `s` on(`s`.`contract_id` = `cp`.`contract_id` and !(`cp`.`number` in (select `sp2`.`number` from (`subscriber_phonebook` `sp2` join `voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `cp`.`contract_id` and `sp2`.`shared` = 0)))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -2433,7 +2439,7 @@ DELIMITER ; /*!50001 SET collation_connection = utf8mb3_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `v_subscriber_phonebook` AS select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from `subscriber_phonebook` `sp` where `sp`.`shared` = 0 union all select `sp`.`id` AS `id`,`ss`.`id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from (((`subscriber_phonebook` `sp` join `voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id`)) join `contracts` `c` on(`c`.`id` = `s`.`contract_id`)) join `voip_subscribers` `ss` on(`ss`.`contract_id` = `c`.`id` and !(`sp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)) and !(`sp`.`number` in (select `sp2`.`number` from (`subscriber_phonebook` `sp2` join `voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `ss`.`contract_id` and `sp2`.`shared` = 0)))) where `sp`.`shared` = 1 union all select concat('c',`cp`.`id`,'s',`s`.`id`) AS `CONCAT("c", cp.id, "s", s.id)`,`s`.`id` AS `subscriber_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared` from (`contract_phonebook` `cp` join `voip_subscribers` `s` on(`s`.`contract_id` = `cp`.`contract_id` and !(`cp`.`number` in (select `sp2`.`number` from (`subscriber_phonebook` `sp2` join `voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `cp`.`contract_id` and `sp2`.`shared` = 0)))) union all select concat('r',`rp`.`id`,'s',`s`.`id`) AS `CONCAT("r", rp.id, "s", s.id)`,`s`.`id` AS `subscriber_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared` from (((`reseller_phonebook` `rp` join `contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `contracts` `c` on(`c`.`contact_id` = `cc`.`id`)) join `voip_subscribers` `s` on(`s`.`contract_id` = `c`.`id` and !(`rp`.`number` in (select `cp2`.`number` from `contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`)) and !(`rp`.`number` in (select `sp2`.`number` from (`subscriber_phonebook` `sp2` join `voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `c`.`id`)))) */; +/*!50001 VIEW `v_subscriber_phonebook` AS select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,1 AS `own` from `billing`.`subscriber_phonebook` `sp` union all select concat('s',`sp`.`id`,'s',`ss`.`id`) AS `CONCAT("s", sp.id, "s", ss.id)`,`ss`.`id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,0 AS `own` from ((((`billing`.`subscriber_phonebook` `sp` join `billing`.`voip_subscribers` `s` on(`s`.`id` = `sp`.`subscriber_id`)) join `billing`.`contracts` `c` on(`c`.`id` = `s`.`contract_id`)) join `billing`.`voip_subscribers` `ss` on(`ss`.`contract_id` = `c`.`id`)) join `provisioning`.`voip_subscribers` `ps` on(`ps`.`uuid` = `ss`.`uuid` and `ps`.`is_pbx_group` = 0 and !(`sp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `s`.`contract_id`)) and !(`sp`.`number` in (select `sp2`.`number` from `billing`.`subscriber_phonebook` `sp2` where `sp2`.`subscriber_id` = `ss`.`id`)))) where `sp`.`shared` = 1 union all select concat('c',`cp`.`id`,'s',`s`.`id`) AS `CONCAT("c", cp.id, "s", s.id)`,`s`.`id` AS `subscriber_id`,`cp`.`number` AS `number`,`cp`.`name` AS `name`,0 AS `shared`,0 AS `own` from ((`billing`.`contract_phonebook` `cp` join `billing`.`voip_subscribers` `s` on(`s`.`contract_id` = `cp`.`contract_id`)) join `provisioning`.`voip_subscribers` `ps` on(`ps`.`uuid` = `s`.`uuid` and `ps`.`is_pbx_group` = 0 and !(`cp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `cp`.`contract_id` and `sp2`.`shared` = 0)))) union all select concat('r',`rp`.`id`,'s',`s`.`id`) AS `CONCAT("r", rp.id, "s", s.id)`,`s`.`id` AS `subscriber_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared`,0 AS `own` from ((((`billing`.`reseller_phonebook` `rp` join `billing`.`contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `billing`.`contracts` `c` on(`c`.`contact_id` = `cc`.`id`)) join `billing`.`voip_subscribers` `s` on(`s`.`contract_id` = `c`.`id`)) join `provisioning`.`voip_subscribers` `ps` on(`ps`.`uuid` = `s`.`uuid` and `ps`.`is_pbx_group` = 0 and !(`rp`.`number` in (select `cp2`.`number` from `billing`.`contract_phonebook` `cp2` where `cp2`.`contract_id` = `c`.`id`)) and !(`rp`.`number` in (select `sp2`.`number` from (`billing`.`subscriber_phonebook` `sp2` join `billing`.`voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `c`.`id`)))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -2446,7 +2452,7 @@ DELIMITER ; /*!50001 SET collation_connection = utf8mb3_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `v_subscriber_reseller_phonebook` AS select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared` from `subscriber_phonebook` `sp` union all select concat('r',`rp`.`id`,'s',`s`.`id`) AS `CONCAT("r", rp.id, "s", s.id)`,`s`.`id` AS `subscriber_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared` from (((`reseller_phonebook` `rp` join `contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `contracts` `c` on(`c`.`contact_id` = `cc`.`id`)) join `voip_subscribers` `s` on(`s`.`contract_id` = `c`.`id` and !(`rp`.`number` in (select `sp2`.`number` from (`subscriber_phonebook` `sp2` join `voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `c`.`id`)))) */; +/*!50001 VIEW `v_subscriber_reseller_phonebook` AS select `sp`.`id` AS `id`,`sp`.`subscriber_id` AS `subscriber_id`,`sp`.`number` AS `number`,`sp`.`name` AS `name`,`sp`.`shared` AS `shared`,1 AS `own` from `subscriber_phonebook` `sp` union all select concat('r',`rp`.`id`,'s',`s`.`id`) AS `CONCAT("r", rp.id, "s", s.id)`,`s`.`id` AS `subscriber_id`,`rp`.`number` AS `number`,`rp`.`name` AS `name`,0 AS `shared`,0 AS `own` from (((`reseller_phonebook` `rp` join `contacts` `cc` on(`cc`.`reseller_id` = `rp`.`reseller_id`)) join `contracts` `c` on(`c`.`contact_id` = `cc`.`id`)) join `voip_subscribers` `s` on(`s`.`contract_id` = `c`.`id` and !(`rp`.`number` in (select `sp2`.`number` from (`subscriber_phonebook` `sp2` join `voip_subscribers` `s2` on(`s2`.`id` = `sp2`.`subscriber_id`)) where `s2`.`contract_id` = `c`.`id`)))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; diff --git a/schema/ngcp.sql b/schema/ngcp.sql index e474cd98..31e61179 100644 --- a/schema/ngcp.sql +++ b/schema/ngcp.sql @@ -24,7 +24,7 @@ CREATE TABLE `db_schema` ( PRIMARY KEY (`id`), UNIQUE KEY `rev_idx` (`revision`,`node`), KEY `release_idx` (`release`) -) ENGINE=InnoDB AUTO_INCREMENT=908 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB AUTO_INCREMENT=909 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8mb4 */; @@ -30958,6 +30958,7 @@ INSERT INTO `db_schema` VALUES (904,15841,'spce','1970-01-01 00:00:01','trunk'); INSERT INTO `db_schema` VALUES (905,15842,'spce','1970-01-01 00:00:01','trunk'); INSERT INTO `db_schema` VALUES (906,15859,'spce','1970-01-01 00:00:01','trunk'); INSERT INTO `db_schema` VALUES (907,15862,'spce','1970-01-01 00:00:01','trunk'); +INSERT INTO `db_schema` VALUES (908,15864,'spce','1970-01-01 00:00:01','trunk'); commit; set autocommit=0; INSERT INTO `timezone` VALUES ('1','localtime','1970-01-01 00:00:01','1970-01-01 00:00:01',NULL);