Files
cbsnexora-backend/mifosng-db/0001a-mifos-platform-base-ddl-schema.sql
T

672 lines
28 KiB
SQL

-- This script is the core DDL for mifos platform
-- Its includes tables related to lookup/reference data, user administration, organisation modeling, client and loans
-- and infrastructure tables needed for 'additional data' and 'screen based reporting' functionality.
-- It does not include DDL customisations needed for specific 'tenants' for 'additional data' functionality around clients/loans.
-- This script drops all tables and re-creates from scratch.
-- drop tables in base-schema
SET foreign_key_checks = 0;
-- portfolio related tables
DROP TABLE IF EXISTS `m_note`;
DROP TABLE IF EXISTS `m_loan_transaction`;
DROP TABLE IF EXISTS `m_loan_charge`;
DROP TABLE IF EXISTS `m_loan_repayment_schedule`;
DROP TABLE IF EXISTS `m_loan`;
DROP TABLE IF EXISTS `m_deposit_account`;
DROP TABLE IF EXISTS `m_group_client`;
DROP TABLE IF EXISTS `m_client`;
DROP TABLE IF EXISTS `m_group`;
DROP TABLE IF EXISTS `m_product_loan`;
DROP TABLE IF EXISTS `m_product_savings`;
DROP TABLE IF EXISTS `m_product_deposit`;
-- organisation related tables
DROP TABLE IF EXISTS `m_organisation_currency`;
DROP TABLE IF EXISTS `m_fund`;
DROP TABLE IF EXISTS `m_charge`;
DROP TABLE IF EXISTS `m_product_loan_charge`;
DROP TABLE IF EXISTS `m_office_transaction`;
DROP TABLE IF EXISTS `m_office`;
DROP TABLE IF EXISTS `m_staff`;
-- admin tables
DROP TABLE IF EXISTS `m_role_permission`;
DROP TABLE IF EXISTS `m_appuser_role`;
DROP TABLE IF EXISTS `m_appuser`;
DROP TABLE IF EXISTS `m_permission`;
DROP TABLE IF EXISTS `m_role`;
-- drop reference/lookup tables
DROP TABLE IF EXISTS `m_currency`;
DROP TABLE IF EXISTS `ref_loan_transaction_processing_strategy`;
DROP TABLE IF EXISTS `m_code_value`;
DROP TABLE IF EXISTS `m_code`;
DROP TABLE IF EXISTS `r_enum_value`;
-- additional data and report tables
DROP TABLE IF EXISTS `stretchydata_dataset_fields`;
DROP TABLE IF EXISTS `stretchydata_dataset`;
DROP TABLE IF EXISTS `stretchydata_datasettype`;
DROP TABLE IF EXISTS `stretchy_parameter`;
DROP TABLE IF EXISTS `stretchy_report_parameter`;
DROP TABLE IF EXISTS `stretchy_report`;
DROP TABLE IF EXISTS `rpt_sequence`;
SET foreign_key_checks = 1;
-- DDL for reference/lookup tables
CREATE TABLE `m_currency` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`code` varchar(3) NOT NULL,
`decimal_places` smallint(5) NOT NULL,
`display_symbol` varchar(10) DEFAULT NULL,
`name` varchar(50) NOT NULL,
`internationalized_name_code` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `ref_loan_transaction_processing_strategy` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`code` varchar(100) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ltp_strategy_code` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_code` (
`id` int NOT NULL AUTO_INCREMENT,
`code_name` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `code_name` (`code_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_code_value` (
`id` int NOT NULL AUTO_INCREMENT,
`code_id` int NOT NULL,
`code_value` varchar(100) DEFAULT NULL,
`order_position` int NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `code_value` (`code_id`, `code_value`),
KEY `FKCFCEA42640BE071Z` (`code_id`),
CONSTRAINT `FKCFCEA42640BE071Z` FOREIGN KEY (`code_id`) REFERENCES `m_code` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*not a major table - just intended for database reporting use for enums and values that would be hidden in java*/
CREATE TABLE `r_enum_value` (
`enum_name` varchar(100) NOT NULL,
`enum_id` int NOT NULL,
`enum_message_property` varchar(100) NOT NULL,
`enum_value` varchar(100) NOT NULL,
PRIMARY KEY (`enum_name`, `enum_id`),
UNIQUE KEY `enum_message_property` (`enum_name`, `enum_message_property`),
UNIQUE KEY `enum_value` (`enum_name`, `enum_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- DDL for organisation wide related concepts
CREATE TABLE `m_fund` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`external_id` varchar(100) DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `fund_name_org` (`name`),
UNIQUE KEY `fund_externalid_org` (`external_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_charge` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT NULL,
`currency_code` varchar(3) NOT NULL,
`charge_applies_to_enum` smallint(5) NOT NULL,
`charge_time_enum` smallint(5) NOT NULL,
`charge_calculation_enum` smallint(5) NOT NULL,
`amount` decimal(19,6) NOT NULL,
`is_active` tinyint(1) NOT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_staff` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`firstname` varchar(50) DEFAULT NULL,
`lastname` varchar(50) DEFAULT NULL,
`display_name` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `display_name` (`display_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_office` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`parent_id` bigint(20) DEFAULT NULL,
`hierarchy` varchar(100) DEFAULT NULL,
`external_id` varchar(100) DEFAULT NULL,
`name` varchar(50) NOT NULL,
`opening_date` date NOT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name_org` (`name`),
UNIQUE KEY `externalid_org` (`external_id`),
KEY `FK2291C477E2551DCC` (`parent_id`),
CONSTRAINT `FK2291C477E2551DCC` FOREIGN KEY (`parent_id`) REFERENCES `m_office` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_office_transaction` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`from_office_id` bigint(20) DEFAULT NULL,
`to_office_id` bigint(20) DEFAULT NULL,
`currency_code` varchar(3) NOT NULL,
`currency_digits` int(11) NOT NULL,
`transaction_amount` decimal(19,6) NOT NULL,
`transaction_date` date NOT NULL,
`description` varchar(100) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK1E37728B93C6C1B6` (`to_office_id`),
KEY `FK1E37728B783C5C25` (`from_office_id`),
CONSTRAINT `FK1E37728B783C5C25` FOREIGN KEY (`from_office_id`) REFERENCES `m_office` (`id`),
CONSTRAINT `FK1E37728B93C6C1B6` FOREIGN KEY (`to_office_id`) REFERENCES `m_office` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_organisation_currency` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`code` varchar(3) NOT NULL,
`decimal_places` smallint(5) NOT NULL,
`name` varchar(50) NOT NULL,
`display_symbol` varchar(10) DEFAULT NULL,
`internationalized_name_code` varchar(50) NOT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- DDL for admin tables
CREATE TABLE `m_permission` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_enum` smallint(5) NOT NULL,
`code` varchar(100) NOT NULL,
`default_description` varchar(500) NOT NULL,
`default_name` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_role` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`description` varchar(500) NOT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_appuser` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`is_deleted` TINYINT(1) DEFAULT 0 NOT NULL,
`office_id` bigint(20) DEFAULT NULL,
`username` varchar(100) NOT NULL,
`firstname` varchar(100) NOT NULL,
`lastname` varchar(100) NOT NULL,
`password` varchar(255) NOT NULL,
`email` varchar(100) NOT NULL,
`firsttime_login_remaining` bit(1) NOT NULL,
`nonexpired` bit(1) NOT NULL,
`nonlocked` bit(1) NOT NULL,
`nonexpired_credentials` bit(1) NOT NULL,
`enabled` bit(1) NOT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username_org` (`username`),
KEY `FKB3D587CE0DD567A` (`office_id`),
CONSTRAINT `FKB3D587CE0DD567A` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_role_permission` (
`role_id` bigint(20) NOT NULL,
`permission_id` bigint(20) NOT NULL,
PRIMARY KEY (`role_id`,`permission_id`),
KEY `FK8DEDB04815CEC7AB` (`role_id`),
KEY `FK8DEDB048103B544B` (`permission_id`),
CONSTRAINT `FK8DEDB048103B544B` FOREIGN KEY (`permission_id`) REFERENCES `m_permission` (`id`),
CONSTRAINT `FK8DEDB04815CEC7AB` FOREIGN KEY (`role_id`) REFERENCES `m_role` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_appuser_role` (
`appuser_id` bigint(20) NOT NULL,
`role_id` bigint(20) NOT NULL,
PRIMARY KEY (`appuser_id`,`role_id`),
KEY `FK7662CE59B4100309` (`appuser_id`),
KEY `FK7662CE5915CEC7AB` (`role_id`),
CONSTRAINT `FK7662CE5915CEC7AB` FOREIGN KEY (`role_id`) REFERENCES `m_role` (`id`),
CONSTRAINT `FK7662CE59B4100309` FOREIGN KEY (`appuser_id`) REFERENCES `m_appuser` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- DDL for portfolio tables
CREATE TABLE `m_group` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT NULL,
`external_id` varchar(100) DEFAULT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
UNIQUE KEY `external_id` (`external_id`),
KEY `FKJPWG000000000003` (`createdby_id`),
KEY `FKJPWG000000000004` (`lastmodifiedby_id`),
CONSTRAINT `FKJPWG000000000003` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FKJPWG000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_client` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`is_deleted` tinyint(1) NOT NULL DEFAULT 0,
`office_id` bigint(20) NOT NULL,
`external_id` varchar(100) DEFAULT NULL,
`firstname` varchar(50) DEFAULT NULL,
`lastname` varchar(50) DEFAULT NULL,
`joining_date` date DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `external_id` (`external_id`),
KEY `FKCE00CAB3E0DD567A` (`office_id`),
KEY `FKAUD0000000000001` (`createdby_id`),
KEY `FKAUD0000000000002` (`lastmodifiedby_id`),
CONSTRAINT `FKAUD0000000000001` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FKAUD0000000000002` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FKCE00CAB3E0DD567A` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_group_client` (
`group_id` bigint(20) NOT NULL,
`client_id` bigint(20) NOT NULL,
PRIMARY KEY (`group_id`,`client_id`),
KEY `client_id` (`client_id`),
CONSTRAINT `m_group_client_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `m_group` (`id`),
CONSTRAINT `m_group_client_ibfk_2` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_product_loan` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`currency_code` varchar(3) NOT NULL,
`currency_digits` smallint(5) NOT NULL,
`principal_amount` decimal(19,6) NOT NULL,
`arrearstolerance_amount` decimal(19,6) NOT NULL,
`name` varchar(100) NOT NULL,
`description` varchar(500) DEFAULT NULL,
`fund_id` bigint(20) DEFAULT NULL,
`loan_transaction_strategy_id` bigint(20) DEFAULT NULL,
`nominal_interest_rate_per_period` decimal(19,6) NOT NULL,
`interest_period_frequency_enum` smallint(5) NOT NULL,
`annual_nominal_interest_rate` decimal(19,6) NOT NULL,
`interest_method_enum` smallint(5) NOT NULL,
`interest_calculated_in_period_enum` smallint(5) NOT NULL DEFAULT '1',
`repay_every` smallint(5) NOT NULL,
`repayment_period_frequency_enum` smallint(5) NOT NULL,
`number_of_repayments` smallint(5) NOT NULL,
`amortization_method_enum` smallint(5) NOT NULL,
`flexible_repayment_schedule` bit(1) NOT NULL,
`interest_rebate` bit(1) NOT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKAUD0000000000003` (`createdby_id`),
KEY `FKAUD0000000000004` (`lastmodifiedby_id`),
KEY `FKA6A8A7D77240145` (`fund_id`),
KEY `FK_ltp_strategy` (`loan_transaction_strategy_id`),
CONSTRAINT `FKA6A8A7D77240145` FOREIGN KEY (`fund_id`) REFERENCES `m_fund` (`id`),
CONSTRAINT `FKAUD0000000000003` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FKAUD0000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FK_ltp_strategy` FOREIGN KEY (`loan_transaction_strategy_id`) REFERENCES `ref_loan_transaction_processing_strategy` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_product_loan_charge` (
`product_loan_id` bigint(20) NOT NULL,
`charge_id` bigint(20) NOT NULL,
PRIMARY KEY (`product_loan_id`,`charge_id`),
KEY `charge_id` (`charge_id`),
CONSTRAINT `m_product_loan_charge_ibfk_1` FOREIGN KEY (`charge_id`) REFERENCES `m_charge` (`id`),
CONSTRAINT `m_product_loan_charge_ibfk_2` FOREIGN KEY (`product_loan_id`) REFERENCES `m_product_loan` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_loan` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`external_id` varchar(100) DEFAULT NULL,
`client_id` bigint(20) NOT NULL,
`product_id` bigint(20) DEFAULT NULL,
`fund_id` bigint(20) DEFAULT NULL,
`loan_transaction_strategy_id` bigint(20) DEFAULT NULL,
`loan_status_id` smallint(5) NOT NULL,
`currency_code` varchar(3) NOT NULL,
`currency_digits` smallint(5) NOT NULL,
`principal_amount` decimal(19,6) NOT NULL,
`arrearstolerance_amount` decimal(19,6) NOT NULL,
`nominal_interest_rate_per_period` decimal(19,6) NOT NULL,
`interest_period_frequency_enum` smallint(5) NOT NULL,
`annual_nominal_interest_rate` decimal(19,6) NOT NULL,
`interest_method_enum` smallint(5) NOT NULL,
`interest_calculated_in_period_enum` smallint(5) NOT NULL DEFAULT '1',
`term_frequency` smallint(5) NOT NULL,
`term_period_frequency_enum` smallint(5) NOT NULL,
`repay_every` smallint(5) NOT NULL,
`repayment_period_frequency_enum` smallint(5) NOT NULL,
`number_of_repayments` smallint(5) NOT NULL,
`amortization_method_enum` smallint(5) NOT NULL,
`flexible_repayment_schedule` bit(1) NOT NULL,
`interest_rebate` bit(1) NOT NULL,
`interest_rebate_amount` decimal(19,6) DEFAULT NULL,
`submittedon_date` datetime DEFAULT NULL,
`approvedon_date` datetime DEFAULT NULL,
`expected_disbursedon_date` date DEFAULT NULL,
`expected_firstrepaymenton_date` date DEFAULT NULL,
`interest_calculated_from_date` date DEFAULT NULL,
`disbursedon_date` date DEFAULT NULL,
`expected_maturedon_date` date DEFAULT NULL,
`maturedon_date` date DEFAULT NULL,
`closedon_date` datetime DEFAULT NULL,
`rejectedon_date` datetime DEFAULT NULL,
`rescheduledon_date` datetime DEFAULT NULL,
`withdrawnon_date` datetime DEFAULT NULL,
`writtenoffon_date` datetime DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `m_id` (`external_id`),
KEY `FKB6F935D87179A0CB` (`client_id`),
KEY `FKB6F935D8C8D4B434` (`product_id`),
KEY `FK7C885877240145` (`fund_id`),
KEY `FK_loan_ltp_strategy` (`loan_transaction_strategy_id`),
CONSTRAINT `FK_loan_ltp_strategy` FOREIGN KEY (`loan_transaction_strategy_id`) REFERENCES `ref_loan_transaction_processing_strategy` (`id`),
CONSTRAINT `FK7C885877240145` FOREIGN KEY (`fund_id`) REFERENCES `m_fund` (`id`),
CONSTRAINT `FKB6F935D87179A0CB` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`),
CONSTRAINT `FKB6F935D8C8D4B434` FOREIGN KEY (`product_id`) REFERENCES `m_product_loan` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_loan_charge` (
`loan_id` bigint(20) NOT NULL,
`charge_id` bigint(20) NOT NULL,
`charge_time_enum` smallint(5) NOT NULL,
`charge_calculation_enum` smallint(5) NOT NULL,
`amount` decimal(19,6) NOT NULL,
PRIMARY KEY (`loan_id`,`charge_id`),
KEY `charge_id` (`charge_id`),
CONSTRAINT `m_loan_charge_ibfk_1` FOREIGN KEY (`charge_id`) REFERENCES `m_charge` (`id`),
CONSTRAINT `m_loan_charge_ibfk_2` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_loan_repayment_schedule` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`loan_id` bigint(20) NOT NULL,
`duedate` date DEFAULT NULL,
`installment` smallint(5) DEFAULT NULL,
`principal_amount` decimal(19,6) DEFAULT NULL,
`principal_completed_derived` decimal(19,6) DEFAULT NULL,
`interest_amount` decimal(19,6) DEFAULT NULL,
`interest_completed_derived` decimal(19,6) DEFAULT NULL,
`interest_waived_derived` decimal(19,6) DEFAULT NULL,
`completed_derived` bit(1) NOT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK488B92AA40BE0710` (`loan_id`),
CONSTRAINT `FK488B92AA40BE0710` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_loan_transaction` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`loan_id` bigint(20) NOT NULL,
`transaction_type_enum` smallint(5) NOT NULL,
`contra_id` bigint(20) DEFAULT NULL,
`transaction_date` date NOT NULL,
`amount` decimal(19,6) NOT NULL,
`principal_portion_derived` decimal(19,6) NOT NULL,
`interest_portion_derived` decimal(19,6) NOT NULL,
`interest_waived_derived` decimal(19,6) NOT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKCFCEA42640BE0710` (`loan_id`),
KEY `FKCFCEA426FC69F3F1` (`contra_id`),
CONSTRAINT `FKCFCEA42640BE0710` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`),
CONSTRAINT `FKCFCEA426FC69F3F1` FOREIGN KEY (`contra_id`) REFERENCES `m_loan_transaction` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_product_savings` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`description` varchar(500) DEFAULT NULL,
`currency_code` varchar(3) DEFAULT NULL,
`currency_digits` smallint(5) DEFAULT NULL,
`interest_rate` decimal(19,6) DEFAULT NULL,
`minimum_balance` decimal(19,6) DEFAULT NULL,
`maximum_balance` decimal(19,6) DEFAULT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKJPW0000000000003` (`createdby_id`),
KEY `FKJPW0000000000004` (`lastmodifiedby_id`),
CONSTRAINT `FKJPW0000000000003` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FKJPW0000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_product_deposit` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
`external_id` varchar(100) DEFAULT NULL,
`description` varchar(500) DEFAULT NULL,
`currency_code` varchar(3) NOT NULL,
`currency_digits` smallint(5) NOT NULL,
`minimum_balance` decimal(19,6) DEFAULT NULL,
`maximum_balance` decimal(19,6) DEFAULT NULL,
`tenure_months` int(11) NOT NULL,
`interest_compounded_every` smallint(5) NOT NULL DEFAULT '1',
`interest_compounded_every_period_enum` smallint(5) NOT NULL DEFAULT '2',
`maturity_default_interest_rate` decimal(19,6) NOT NULL,
`maturity_min_interest_rate` decimal(19,6) NOT NULL,
`maturity_max_interest_rate` decimal(19,6) NOT NULL,
`is_renewal_allowed` tinyint(1) NOT NULL DEFAULT '0',
`is_preclosure_allowed` tinyint(1) NOT NULL DEFAULT '0',
`pre_closure_interest_rate` decimal(19,6) NOT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name_deposit_product` (`name`),
UNIQUE KEY `externalid_deposit_product` (`external_id`),
KEY `FKJPW0000000000003` (`createdby_id`),
KEY `FKJPW0000000000004` (`lastmodifiedby_id`),
CONSTRAINT `FKJPX0000000000003` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FKJPX0000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_deposit_account` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
`status_enum` smallint(5) NOT NULL DEFAULT '0',
`external_id` varchar(100) DEFAULT NULL,
`client_id` bigint(20) NOT NULL,
`product_id` bigint(20) NOT NULL,
`currency_code` varchar(3) NOT NULL,
`currency_digits` smallint(5) NOT NULL,
`deposit_amount` decimal(19,6) DEFAULT NULL,
`maturity_nominal_interest_rate` decimal(19,6) NOT NULL,
`tenure_months` int(11) NOT NULL,
`interest_compounded_every` smallint(5) NOT NULL DEFAULT '1',
`interest_compounded_every_period_enum` smallint(5) NOT NULL DEFAULT '2',
`projected_commencement_date` date NOT NULL,
`actual_commencement_date` date DEFAULT NULL,
`projected_maturity_date` date NOT NULL,
`actual_maturity_date` date DEFAULT NULL,
`projected_interest_accrued_on_maturity` decimal(19,6) NOT NULL,
`actual_interest_accrued` decimal(19,6) DEFAULT NULL,
`projected_total_maturity_amount` decimal(19,6) NOT NULL,
`actual_total_amount` decimal(19,6) DEFAULT NULL,
`is_renewal_allowed` tinyint(1) NOT NULL DEFAULT '0',
`renewed_account_id` bigint(20) DEFAULT NULL,
`is_preclosure_allowed` tinyint(1) NOT NULL DEFAULT '0',
`pre_closure_interest_rate` decimal(19,6) NOT NULL,
`withdrawnon_date` datetime DEFAULT NULL,
`rejectedon_date` datetime DEFAULT NULL,
`closedon_date` datetime DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `deposit_acc_external_id` (`external_id`),
KEY `FKKW0000000000001` (`client_id`),
KEY `FKKW0000000000002` (`product_id`),
KEY `FKKW0000000000003` (`renewed_account_id`),
CONSTRAINT `FKKW0000000000001` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`),
CONSTRAINT `FKKW0000000000002` FOREIGN KEY (`product_id`) REFERENCES `m_product_deposit` (`id`),
CONSTRAINT `FKKW0000000000003` FOREIGN KEY (`renewed_account_id`) REFERENCES `m_deposit_account` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `m_note` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`client_id` bigint(20) NOT NULL,
`loan_id` bigint(20) DEFAULT NULL,
`loan_transaction_id` bigint(20) DEFAULT NULL,
`note_type_enum` smallint(5) NOT NULL,
`note` varchar(1000) DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`createdby_id` bigint(20) DEFAULT NULL,
`lastmodified_date` datetime DEFAULT NULL,
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK7C9708924D26803` (`loan_transaction_id`),
KEY `FK7C97089541F0A56` (`createdby_id`),
KEY `FK7C970897179A0CB` (`client_id`),
KEY `FK7C970898F889C3F` (`lastmodifiedby_id`),
KEY `FK7C9708940BE0710` (`loan_id`),
CONSTRAINT `FK7C9708924D26803` FOREIGN KEY (`loan_transaction_id`) REFERENCES `m_loan_transaction` (`id`),
CONSTRAINT `FK7C9708940BE0710` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`),
CONSTRAINT `FK7C97089541F0A56` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`),
CONSTRAINT `FK7C970897179A0CB` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`),
CONSTRAINT `FK7C970898F889C3F` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- DDL for additional data (aka stretchy data) tables
CREATE TABLE `rpt_sequence` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `stretchydata_datasettype` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `stretchy_parameter` (
`parameter_id` int(11) NOT NULL AUTO_INCREMENT,
`parameter_name` varchar(45) NOT NULL,
`parameter_variable` varchar(45) DEFAULT NULL,
`parameter_label` varchar(45) NOT NULL,
`parameter_displayType` varchar(45) NOT NULL,
`parameter_FormatType` varchar(10) NOT NULL,
`parameter_default` varchar(45) NOT NULL,
`special` varchar(1) DEFAULT NULL,
`selectOne` varchar(1) DEFAULT NULL,
`selectAll` varchar(1) DEFAULT NULL,
`parameter_sql` text,
PRIMARY KEY (`parameter_id`),
UNIQUE KEY `name_UNIQUE` (`parameter_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `stretchydata_dataset` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`datasettype_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `stretchydata_dataset_fk1` (`datasettype_id`,`name`),
CONSTRAINT `stretchydata_dataset` FOREIGN KEY (`datasettype_id`) REFERENCES `stretchydata_datasettype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `stretchydata_dataset_fields` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`data_type` varchar(15) NOT NULL,
`data_length` int(11) DEFAULT NULL,
`display_type` varchar(45) DEFAULT NULL,
`dataset_id` int(11) NOT NULL,
`code_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `stretchydata_dataset_fields_fk1` (`dataset_id`,`name`),
KEY `stretchydata_dataset_fields_fk2` (`code_id`),
CONSTRAINT `stretchydata_dataset_fields_fk2` FOREIGN KEY (`code_id`) REFERENCES `m_code` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `stretchydata_dataset_fields_fk1` FOREIGN KEY (`dataset_id`) REFERENCES `stretchydata_dataset` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `stretchy_report` (
`report_id` int(11) NOT NULL AUTO_INCREMENT,
`report_name` varchar(100) NOT NULL,
`report_type` varchar(20) NOT NULL,
`report_subtype` varchar(20) DEFAULT NULL,
`report_category` varchar(45) DEFAULT NULL,
`report_sql` text,
`description` text,
`core_report` tinyint(1) DEFAULT '0',
`use_report` tinyint(1) DEFAULT '0',
PRIMARY KEY (`report_id`),
UNIQUE KEY `report_name_UNIQUE` (`report_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `stretchy_report_parameter` (
`report_id` int(11) NOT NULL,
`parameter_id` int(11) NOT NULL,
`report_parameter_name` varchar(45) DEFAULT NULL,
PRIMARY KEY (`report_id`,`parameter_id`),
UNIQUE KEY `report_id_name_UNIQUE` (`report_id`,`report_parameter_name`)
) ENGINE=InnoDB CHARSET=utf8;