From a2332429ce92f4972f07b15e068dbe7de3aa8006 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Sat, 27 Jul 2013 13:08:25 +0200 Subject: [PATCH] Move reseller_id to contact. At the same time, we make ossbss force a contact for each contract, so resellers can manage their own contacts. --- db_scripts/diff/13832.up | 10 ---------- db_scripts/diff/13837.up | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) delete mode 100644 db_scripts/diff/13832.up create mode 100644 db_scripts/diff/13837.up diff --git a/db_scripts/diff/13832.up b/db_scripts/diff/13832.up deleted file mode 100644 index 44fdf2a8..00000000 --- a/db_scripts/diff/13832.up +++ /dev/null @@ -1,10 +0,0 @@ -USE billing; -SET AUTOCOMMIT=0; - -INSERT INTO contacts VALUES(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, now(), now(), NULL); - -SELECT LAST_INSERT_ID() INTO @contact_id; - -UPDATE contracts c, resellers r SET c.contact_id = @contact_id WHERE c.id = r.contract_id and c.contact_id IS NULL; - -COMMIT; diff --git a/db_scripts/diff/13837.up b/db_scripts/diff/13837.up new file mode 100644 index 00000000..52cf8808 --- /dev/null +++ b/db_scripts/diff/13837.up @@ -0,0 +1,16 @@ +USE billing; + +-- move the reseller_id from contract to contact to be able to properly +-- enforce contacts and be able to manage contacts for resellers + +ALTER TABLE contacts ADD COLUMN reseller_id INT(11) UNSIGNED DEFAULT NULL AFTER id; +INSERT INTO contacts(email) VALUES('default-customer@default.invalid'); +SELECT LAST_INSERT_ID() INTO @cid; +UPDATE contacts SET reseller_id = 1 WHERE id = @cid; +ALTER TABLE contacts ADD CONSTRAINT ct_resellerid_ref FOREIGN KEY(reseller_id) REFERENCES resellers(id) ON DELETE CASCADE ON UPDATE CASCADE; + +UPDATE contracts SET contact_id = @cid WHERE contact_id IS NULL; +ALTER TABLE contracts DROP FOREIGN KEY co_resellerid_ref; +ALTER TABLE contracts DROP COLUMN reseller_id; +ALTER TABLE contracts DROP FOREIGN KEY co_contactid_ref; +ALTER TABLE contracts ADD CONSTRAINT co_contactid_ref FOREIGN KEY(contact_id) REFERENCES contacts(id) ON DELETE RESTRICT ON UPDATE CASCADE;