INSERT INTO PaymentTypeMaster(id, payment_class_id, name) VALUES (8, 2, 'Value-dated Payment');

-- adding a column to LoanDemand for soft-delete purposes
ALTER TABLE `LoanDemand` ADD COLUMN `is_valid` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1  AFTER `unpaid_amount` ;
ALTER TABLE `LoanDemandUnpaid` ADD COLUMN `is_valid` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1  AFTER `unpaid_amount` ;

ALTER TABLE `LoanPayment` 
ADD COLUMN `related_payment_id` INTEGER UNSIGNED DEFAULT NULL  AFTER `status` , 
  ADD FOREIGN KEY (`related_payment_id` )
  REFERENCES `LoanPayment` (`id` )
  ON DELETE NO ACTION
  ON UPDATE CASCADE
, ADD INDEX `related_payment_id` (`related_payment_id` ASC) ;

-- adding effective_date end_date to GLABH
ALTER TABLE `GLAccountBalanceHistory` 
ADD COLUMN `effective_date` DATE NOT NULL  AFTER `date` 
, ADD COLUMN `end_date` DATE NULL  AFTER `effective_date` 
, DROP PRIMARY KEY 
, ADD PRIMARY KEY (`gl_account_id`, `date`, `effective_date`) ;
-- updating effective_date
UPDATE GLAccountBalanceHistory SET effective_date = date;