From 546e480496bbe15afbc79b8bbc93c07f61a6b10f Mon Sep 17 00:00:00 2001 From: Vishwas Babu A J Date: Tue, 10 Sep 2013 09:01:39 +0530 Subject: [PATCH] db changes for mapping savings transactions to an office --- ...__track_savings_transaction_against_office.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 mifosng-db/migrations/core_db/V113__track_savings_transaction_against_office.sql diff --git a/mifosng-db/migrations/core_db/V113__track_savings_transaction_against_office.sql b/mifosng-db/migrations/core_db/V113__track_savings_transaction_against_office.sql new file mode 100644 index 000000000..c6222f9be --- /dev/null +++ b/mifosng-db/migrations/core_db/V113__track_savings_transaction_against_office.sql @@ -0,0 +1,15 @@ +ALTER TABLE `m_savings_account_transaction` + ADD COLUMN `office_id` BIGINT(20) NULL DEFAULT NULL AFTER `savings_account_id`; + +/**update client savings**/ +UPDATE m_savings_account_transaction st set st.office_id = (SELECT c.office_id AS officeId FROM m_savings_account sa JOIN m_client c on sa.client_id=c.id where sa.id=st.savings_account_id) where st.savings_account_id in (Select sa.id from m_savings_account sa where sa.client_id is not null); + +/**update group savings**/ +UPDATE m_savings_account_transaction st set st.office_id = (SELECT g.office_id AS officeId FROM m_savings_account sa JOIN m_group g on sa.group_id=g.id where sa.id=st.savings_account_id) where st.savings_account_id in (Select sa.id from m_savings_account sa where sa.group_id is not null); + +/**Add foreign key constraints**/ +ALTER TABLE `m_savings_account_transaction` + CHANGE COLUMN `office_id` `office_id` BIGINT(20) NOT NULL AFTER `savings_account_id`; + +ALTER TABLE `m_savings_account_transaction` + ADD CONSTRAINT `FK_m_savings_account_transaction_m_office` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`); \ No newline at end of file