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.
vseva/pbx_groups
Andreas Granig 12 years ago
parent 192b66281a
commit a2332429ce

@ -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;

@ -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;
Loading…
Cancel
Save