From 1bfed9cde7b93874eb8b58cbb0cf6623b1cb37ff Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Thu, 24 May 2018 16:21:56 +0200 Subject: [PATCH] Revert "TT#35662 move product_id to billing.contracts" This reverts commit 57d32431c8649b92dad0bd1ff4bbddef7324d580. Change-Id: I14e3607d038694fc128475f1ecc78a8e7ab4272e --- db_scripts/diff/15394.down | 3 --- db_scripts/diff/15394.up | 31 ------------------------------- 2 files changed, 34 deletions(-) delete mode 100644 db_scripts/diff/15394.down delete mode 100644 db_scripts/diff/15394.up diff --git a/db_scripts/diff/15394.down b/db_scripts/diff/15394.down deleted file mode 100644 index 0d2482e8..00000000 --- a/db_scripts/diff/15394.down +++ /dev/null @@ -1,3 +0,0 @@ -use billing; - -alter table contracts drop column product_id; diff --git a/db_scripts/diff/15394.up b/db_scripts/diff/15394.up deleted file mode 100644 index d2a9cc01..00000000 --- a/db_scripts/diff/15394.up +++ /dev/null @@ -1,31 +0,0 @@ -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; -