diff --git a/db_scripts/diff/15580_not_replicated.down b/db_scripts/diff/15580_not_replicated.down new file mode 100644 index 00000000..d0621869 --- /dev/null +++ b/db_scripts/diff/15580_not_replicated.down @@ -0,0 +1,4 @@ +SET sql_log_bin=0; +use billing; + +drop function get_lnp_number_id; diff --git a/db_scripts/diff/15580_not_replicated.up b/db_scripts/diff/15580_not_replicated.up new file mode 100644 index 00000000..08ce291b --- /dev/null +++ b/db_scripts/diff/15580_not_replicated.up @@ -0,0 +1,38 @@ +SET sql_log_bin=0; +use billing; + +delimiter ;; + +create function get_lnp_number_id( + _destination varchar(511), + _epoch decimal(13,3) +) returns int(11) +deterministic reads sql data +begin + + declare _destination_prefix varchar(511); + declare _i int(3); + declare _number_id int(11); + + set _i = length(_destination); + + destination_loop: loop + if _i < 0 or _number_id is not null then + leave destination_loop; + end if; + set _destination_prefix = substr(coalesce(_destination,""),1,_i); + set _number_id = (select id from billing.lnp_numbers + use index (number_idx) + where number = _destination_prefix + and (start <= from_unixtime(_epoch) or start is null) + and (end > from_unixtime(_epoch) or end is null) + limit 1); + set _i = _i - 1; + end loop destination_loop; + + return _number_id; + +end;; + +delimiter ; +