to prevent a pontential foreign key error in susequent
alter table billing_fees_raw
..,
add unique key bfr_srcdestdir_idx (billing_profile_id, type,
match_mode, direction, source, destination),
..;
the key is turned into not-unique afterwards with 15449.up
Change-Id: I884adc442e48202fd0061fece400f5fcb6f892b5
select group_concat(column_name) into columns from information_schema.columns where table_schema = database() and table_name = "billing_fees_raw" and column_name not in ("id");
set @statement = concat("insert into billing.billing_fees(id,",columns,")
select min_id,",columns,"
from billing.billing_fees_raw bnu
from billing.billing_fees_raw bnu
inner join (
select min(i_nu.id) min_id
from billing.billing_fees_raw i_nu
left join billing.billing_fees i_u
on i_nu.billing_profile_id=i_u.billing_profile_id
select min(i_nu.id) min_id
from billing.billing_fees_raw i_nu
left join billing.billing_fees i_u
on i_nu.billing_profile_id=i_u.billing_profile_id
and i_nu.type=i_u.type
and i_nu.match_mode=i_u.match_mode
and i_nu.direction=i_u.direction
and i_nu.source=i_u.source
and i_nu.destination=i_u.destination
and i_nu.match_mode=i_u.match_mode
and i_nu.direction=i_u.direction
and i_nu.source=i_u.source
and i_nu.destination=i_u.destination
where i_u.id is null ",
if( @profile_id is not null, " and i_nu.billing_profile_id = ? ", " and 1 = ? "),
" group by i_nu.billing_profile_id,i_nu.type,i_nu.match_mode,i_nu.direction,i_nu.source,i_nu.destination