You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
db-schema/db_scripts/diff/13837.up

17 lines
905 B

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;