set foreign_key_checks=0;

ALTER TABLE `LoanProduct` ADD COLUMN `cheque_bounce_charge` SMALLINT UNSIGNED DEFAULT 0 AFTER `penalty_rate_type_id`;
ALTER TABLE `LoanAccount` 
ADD COLUMN `foreclosure_penalty_rate` DECIMAL(6,2) DEFAULT NULL AFTER `funding_id` , 
ADD COLUMN `foreclosure_penalty_rate_type_id` TINYINT UNSIGNED DEFAULT NULL , 
ADD CONSTRAINT `LoanAccount_ibfk_9` FOREIGN KEY (foreclosure_penalty_rate_type_id) REFERENCES FeeRateTypeMaster (id) ON DELETE NO ACTION ON UPDATE CASCADE ;

set foreign_key_checks=1;

UPDATE LoanAccount AS LA INNER JOIN LoanProduct AS LP ON (LP.product_id = LA.product_id)
SET LA.foreclosure_penalty_rate = LP.foreclosure_penalty_rate , LA.foreclosure_penalty_rate_type_id = LP.foreclosure_penalty_rate_type_id;
