BEGIN;
CREATE TABLE `espresso_crm`.`crm_payment_invoices` ( `payment_id` BIGINT UNSIGNED NOT NULL DEFAULT '0' , `invoice_id` BIGINT UNSIGNED NOT NULL DEFAULT '0' , UNIQUE `i_p_i`(`payment_id`, `invoice_id`)) ENGINE = InnoDB  CHARSET=utf8 COLLATE utf8_general_ci;
ALTER TABLE `crm_payment_invoices` ADD INDEX(`invoice_id`);
INSERT IGNORE INTO crm_payment_invoices SELECT id, invoice_id FROM crm_payment;
ALTER TABLE crm_payment DROP invoice_id;
COMMIT;
