ALTER TABLE `LoanScheduleDateRef` 
  ADD COLUMN `account_id` MEDIUMINT UNSIGNED DEFAULT NULL  AFTER `num_installments` , 
  ADD CONSTRAINT `LoanScheduleDateRef_ibfk_3` 
  FOREIGN KEY (`account_id`) 
  REFERENCES `LoanAccount` (`id`) 
  ON DELETE NO ACTION 
  ON UPDATE CASCADE;

ALTER TABLE `LoanScheduleDateRef` 
DROP INDEX `loanscheduledateref_num_idx`,
ADD UNIQUE INDEX `loanscheduledateref_num_idx` (`product_id` ASC,`repay_freq_id` ASC,`disbursement_date` ASC,`first_repay_date` ASC,`num_installments` ASC,`account_id` ASC);

