diff --git a/db_scripts/diff/15316.down b/db_scripts/diff/15316.down new file mode 100644 index 00000000..863127f3 --- /dev/null +++ b/db_scripts/diff/15316.down @@ -0,0 +1,7 @@ +USE billing; + +ALTER TABLE contacts DROP timezone; + +DROP VIEW v_subscriber_timezone; +DROP VIEW v_contract_timezone; +DROP VIEW v_reseller_timezone; diff --git a/db_scripts/diff/15316.up b/db_scripts/diff/15316.up new file mode 100644 index 00000000..bf3cee71 --- /dev/null +++ b/db_scripts/diff/15316.up @@ -0,0 +1,30 @@ +USE billing; + +ALTER TABLE contacts ADD timezone VARCHAR(80) DEFAULT NULL; + +CREATE OR REPLACE VIEW v_subscriber_timezone AS + SELECT sc.id as contact_id, s.id as subscriber_id, s.uuid, + COALESCE(sc.timezone, cc.timezone, rc.timezone) as name + FROM voip_subscribers s +LEFT OUTER JOIN contacts sc ON sc.id = s.contact_id +JOIN contracts c ON c.id = s.contract_id +JOIN contacts cc ON cc.id = c.contact_id +JOIN resellers r ON r.id = cc.reseller_id +JOIN contracts i ON i.id = r.contract_id +JOIN contacts rc ON rc.id = i.contact_id; + +CREATE OR REPLACE VIEW v_contract_timezone AS + SELECT cc.id as contact_id, c.id as contract_id, + COALESCE(cc.timezone, rc.timezone) as name + FROM contracts c +JOIN contacts cc ON cc.id = c.contact_id +JOIN resellers r ON r.id = cc.reseller_id +JOIN contracts i ON i.id = r.contract_id +JOIN contacts rc ON rc.id = i.contact_id; + +CREATE OR REPLACE VIEW v_reseller_timezone AS + SELECT rc.id as contact_id, r.id as reseller_id, + rc.timezone as name +FROM resellers r +JOIN contracts i ON i.id = r.contract_id +JOIN contacts rc ON rc.id = i.contact_id;