mirror of https://github.com/sipwise/db-schema.git
Change-Id: I153a6d57d5e0353657fc1facebd1db132f0df811changes/98/20398/8
parent
1260b73d8a
commit
06abcc01e1
@ -0,0 +1,3 @@
|
||||
use billing;
|
||||
|
||||
alter table contracts drop column product_id;
|
@ -0,0 +1,31 @@
|
||||
use billing;
|
||||
|
||||
alter table contracts add column product_id int(11) unsigned default null;
|
||||
|
||||
update
|
||||
contracts c
|
||||
join (
|
||||
select
|
||||
bm1.contract_id,
|
||||
max(bm1.id) as id
|
||||
from
|
||||
billing.billing_mappings bm1
|
||||
join (
|
||||
select
|
||||
bm2.contract_id,
|
||||
max(bm2.start_date) as start_date
|
||||
from
|
||||
billing.billing_mappings bm2
|
||||
where (
|
||||
bm2.end_date >= now() or bm2.end_date is null)
|
||||
and (bm2.start_date <= now() or bm2.start_date is null
|
||||
) group by bm2.contract_id
|
||||
) as mx on bm1.contract_id = mx.contract_id and bm1.start_date <=> mx.start_date
|
||||
group by bm1.contract_id
|
||||
) as bm_actual on bm_actual.contract_id = c.id
|
||||
join
|
||||
billing.billing_mappings bm on bm.id = bm_actual.id
|
||||
set c.product_id = bm.product_id;
|
||||
|
||||
alter table contracts modify column product_id int(11) unsigned not null, add constraint c_productid_ref foreign key (product_id) references products (id) on update cascade;
|
||||
|
Loading…
Reference in new issue