-- Schema: fineract_bk_mifostenant-default
CREATE SCHEMA IF NOT EXISTS "fineract_bk_mifostenant-default";

-- Table: acc_gl_account
CREATE TABLE "fineract_bk_mifostenant-default"."acc_gl_account" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".acc_gl_account_id_seq'::regclass),
    "name" VARCHAR(45) NOT NULL,
    "parent_id" BIGINT,
    "gl_code" VARCHAR(45) NOT NULL,
    "disabled" SMALLINT NOT NULL DEFAULT '0'::smallint,
    "manual_journal_entries_allowed" SMALLINT NOT NULL DEFAULT '1'::smallint,
    "account_usage" SMALLINT NOT NULL DEFAULT '2'::smallint,
    "classification_enum" SMALLINT NOT NULL,
    "description" VARCHAR(500) DEFAULT NULL::character varying,
    CONSTRAINT "acc_gl_account_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "acc_gl_account_gl_code_key" UNIQUE ("gl_code"),
    CONSTRAINT "acc_gl_account_parent_id_key" UNIQUE ("parent_id")
);

-- Table: acc_gl_closure
CREATE TABLE "fineract_bk_mifostenant-default"."acc_gl_closure" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".acc_gl_closure_id_seq'::regclass),
    "office_id" BIGINT NOT NULL,
    "closing_date" DATE NOT NULL,
    "is_deleted" INTEGER NOT NULL DEFAULT 0,
    "createdby_id" BIGINT,
    "lastmodifiedby_id" BIGINT,
    "created_date" TIMESTAMP,
    "lastmodified_date" TIMESTAMP,
    "comments" VARCHAR(500) DEFAULT NULL::character varying,
    CONSTRAINT "acc_gl_closure_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "acc_gl_closure_createdby_id_key" UNIQUE ("createdby_id"),
    CONSTRAINT "acc_gl_closure_lastmodifiedby_id_key" UNIQUE ("lastmodifiedby_id"),
    CONSTRAINT "acc_gl_closure_office_id_closing_date_key" UNIQUE ("office_id", "closing_date"),
    CONSTRAINT "acc_gl_closure_office_id_key" UNIQUE ("office_id")
);

-- Table: acc_gl_journal_entry
CREATE TABLE "fineract_bk_mifostenant-default"."acc_gl_journal_entry" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".acc_gl_journal_entry_id_seq'::regclass),
    "account_id" BIGINT NOT NULL,
    "office_id" BIGINT NOT NULL,
    "reversal_id" BIGINT,
    "transaction_id" VARCHAR(50) NOT NULL,
    "reversed" SMALLINT NOT NULL DEFAULT '0'::smallint,
    "manual_entry" SMALLINT NOT NULL DEFAULT '0'::smallint,
    "entry_date" DATE NOT NULL,
    "type_enum" SMALLINT NOT NULL,
    "amount" NUMERIC(19,6) NOT NULL,
    "description" VARCHAR(500) DEFAULT NULL::character varying,
    "entity_type_enum" SMALLINT,
    "entity_id" BIGINT,
    "createdby_id" BIGINT NOT NULL,
    "lastmodifiedby_id" BIGINT NOT NULL,
    "created_date" TIMESTAMP NOT NULL,
    "lastmodified_date" TIMESTAMP NOT NULL,
    CONSTRAINT "acc_gl_journal_entry_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "acc_gl_journal_entry_account_id_key" UNIQUE ("account_id"),
    CONSTRAINT "acc_gl_journal_entry_createdby_id_key" UNIQUE ("createdby_id"),
    CONSTRAINT "acc_gl_journal_entry_lastmodifiedby_id_key" UNIQUE ("lastmodifiedby_id"),
    CONSTRAINT "acc_gl_journal_entry_office_id_key" UNIQUE ("office_id"),
    CONSTRAINT "acc_gl_journal_entry_reversal_id_key" UNIQUE ("reversal_id")
);

-- Table: acc_product_mapping
CREATE TABLE "fineract_bk_mifostenant-default"."acc_product_mapping" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".acc_product_mapping_id_seq'::regclass),
    "gl_account_id" BIGINT,
    "product_id" BIGINT,
    "product_type" SMALLINT,
    "financial_account_type" SMALLINT,
    CONSTRAINT "acc_product_mapping_pkey" PRIMARY KEY ("id")
);

-- Table: c_configuration
CREATE TABLE "fineract_bk_mifostenant-default"."c_configuration" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".c_configuration_id_seq'::regclass),
    "name" VARCHAR(50) DEFAULT NULL::character varying,
    "enabled" SMALLINT NOT NULL DEFAULT '0'::smallint,
    CONSTRAINT "c_configuration_pkey" PRIMARY KEY ("id")
);

-- Table: extra_client_details
CREATE TABLE "fineract_bk_mifostenant-default"."extra_client_details" (
    "client_id" BIGINT NOT NULL,
    "Business" TEXT,
    "Years" TEXT,
    "Gender_cd" INTEGER,
    "Education_cv" VARCHAR(60) DEFAULT NULL::character varying,
    "Next" TEXT,
    "Highest" TEXT,
    "Comment" TEXT,
    CONSTRAINT "extra_client_details_pkey" PRIMARY KEY ("client_id")
);

-- Table: extra_family_details
CREATE TABLE "fineract_bk_mifostenant-default"."extra_family_details" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".extra_family_details_id_seq'::regclass),
    "client_id" BIGINT NOT NULL,
    "Name" VARCHAR(40) DEFAULT NULL::character varying,
    "Date" TEXT,
    "Points" TEXT,
    "Education_cd_Highest" INTEGER,
    "Other" TEXT,
    CONSTRAINT "extra_family_details_pkey" PRIMARY KEY ("id")
);

-- Table: extra_loan_details
CREATE TABLE "fineract_bk_mifostenant-default"."extra_loan_details" (
    "loan_id" BIGINT NOT NULL,
    "Business" TEXT,
    "Years" TEXT,
    "Gender_cd" INTEGER,
    "Education_cv" VARCHAR(60) DEFAULT NULL::character varying,
    "Next" TEXT,
    "Highest" TEXT,
    "Comment" TEXT,
    CONSTRAINT "extra_loan_details_pkey" PRIMARY KEY ("loan_id")
);

-- Table: m_appuser
CREATE TABLE "fineract_bk_mifostenant-default"."m_appuser" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_appuser_id_seq'::regclass),
    "is_deleted" SMALLINT NOT NULL DEFAULT '0'::smallint,
    "office_id" BIGINT,
    "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" BOOLEAN NOT NULL,
    "nonexpired" BOOLEAN NOT NULL,
    "nonlocked" BOOLEAN NOT NULL,
    "nonexpired_credentials" BOOLEAN NOT NULL,
    "enabled" BOOLEAN NOT NULL,
    CONSTRAINT "m_appuser_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_appuser_office_id_key" UNIQUE ("office_id"),
    CONSTRAINT "m_appuser_username_key" UNIQUE ("username")
);

-- Table: m_appuser_role
CREATE TABLE "fineract_bk_mifostenant-default"."m_appuser_role" (
    "appuser_id" BIGINT NOT NULL,
    "role_id" BIGINT NOT NULL,
    CONSTRAINT "m_appuser_role_pkey" PRIMARY KEY ("appuser_id", "role_id"),
    CONSTRAINT "m_appuser_role_appuser_id_key" UNIQUE ("appuser_id"),
    CONSTRAINT "m_appuser_role_role_id_key" UNIQUE ("role_id")
);

-- Table: m_calendar
CREATE TABLE "fineract_bk_mifostenant-default"."m_calendar" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_calendar_id_seq'::regclass),
    "title" VARCHAR(50) NOT NULL,
    "description" VARCHAR(100) DEFAULT NULL::character varying,
    "location" VARCHAR(50) DEFAULT NULL::character varying,
    "start_date" DATE NOT NULL,
    "end_date" DATE,
    "duration" SMALLINT,
    "calendar_type_enum" SMALLINT NOT NULL,
    "repeating" SMALLINT NOT NULL DEFAULT '0'::smallint,
    "recurrence" VARCHAR(100) DEFAULT NULL::character varying,
    "remind_by_enum" SMALLINT,
    "first_reminder" SMALLINT,
    "second_reminder" SMALLINT,
    "createdby_id" BIGINT,
    "lastmodifiedby_id" BIGINT,
    "created_date" TIMESTAMP,
    "lastmodified_date" TIMESTAMP,
    CONSTRAINT "m_calendar_pkey" PRIMARY KEY ("id")
);

-- Table: m_calendar_instance
CREATE TABLE "fineract_bk_mifostenant-default"."m_calendar_instance" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_calendar_instance_id_seq'::regclass),
    "calendar_id" BIGINT NOT NULL,
    "entity_id" BIGINT NOT NULL,
    "entity_type_enum" SMALLINT NOT NULL,
    CONSTRAINT "m_calendar_instance_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_calendar_instance_calendar_id_key" UNIQUE ("calendar_id")
);

-- Table: m_charge
CREATE TABLE "fineract_bk_mifostenant-default"."m_charge" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_charge_id_seq'::regclass),
    "name" VARCHAR(100) DEFAULT NULL::character varying,
    "currency_code" VARCHAR(3) NOT NULL,
    "charge_applies_to_enum" SMALLINT NOT NULL,
    "charge_time_enum" SMALLINT NOT NULL,
    "charge_calculation_enum" SMALLINT NOT NULL,
    "amount" NUMERIC(19,6) NOT NULL,
    "is_penalty" SMALLINT NOT NULL DEFAULT '0'::smallint,
    "is_active" SMALLINT NOT NULL,
    "is_deleted" SMALLINT NOT NULL DEFAULT '0'::smallint,
    CONSTRAINT "m_charge_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_charge_name_key" UNIQUE ("name")
);

-- Table: m_client
CREATE TABLE "fineract_bk_mifostenant-default"."m_client" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_client_id_seq'::regclass),
    "account_no" VARCHAR(20) NOT NULL,
    "office_id" BIGINT NOT NULL,
    "external_id" VARCHAR(100) DEFAULT NULL::character varying,
    "firstname" VARCHAR(50) DEFAULT NULL::character varying,
    "middlename" VARCHAR(50) DEFAULT NULL::character varying,
    "lastname" VARCHAR(50) DEFAULT NULL::character varying,
    "fullname" VARCHAR(100) DEFAULT NULL::character varying,
    "display_name" VARCHAR(100) NOT NULL,
    "image_key" VARCHAR(500) DEFAULT NULL::character varying,
    "joined_date" DATE,
    "is_deleted" SMALLINT NOT NULL DEFAULT '0'::smallint,
    CONSTRAINT "m_client_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_client_account_no_key" UNIQUE ("account_no"),
    CONSTRAINT "m_client_external_id_key" UNIQUE ("external_id"),
    CONSTRAINT "m_client_office_id_key" UNIQUE ("office_id")
);

-- Table: m_client_identifier
CREATE TABLE "fineract_bk_mifostenant-default"."m_client_identifier" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_client_identifier_id_seq'::regclass),
    "client_id" BIGINT NOT NULL,
    "document_type_id" INTEGER NOT NULL,
    "document_key" VARCHAR(50) NOT NULL,
    "description" VARCHAR(500) DEFAULT NULL::character varying,
    "createdby_id" BIGINT,
    "lastmodifiedby_id" BIGINT,
    "created_date" TIMESTAMP,
    "lastmodified_date" TIMESTAMP,
    CONSTRAINT "m_client_identifier_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_client_identifier_client_id_document_type_id_key" UNIQUE ("client_id", "document_type_id"),
    CONSTRAINT "m_client_identifier_client_id_key" UNIQUE ("client_id"),
    CONSTRAINT "m_client_identifier_document_type_id_document_key_key" UNIQUE ("document_type_id", "document_key"),
    CONSTRAINT "m_client_identifier_document_type_id_key" UNIQUE ("document_type_id")
);

-- Table: m_code
CREATE TABLE "fineract_bk_mifostenant-default"."m_code" (
    "id" INTEGER NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_code_id_seq'::regclass),
    "code_name" VARCHAR(100) DEFAULT NULL::character varying,
    "is_system_defined" SMALLINT NOT NULL DEFAULT '0'::smallint,
    CONSTRAINT "m_code_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_code_code_name_key" UNIQUE ("code_name")
);

-- Table: m_code_value
CREATE TABLE "fineract_bk_mifostenant-default"."m_code_value" (
    "id" INTEGER NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_code_value_id_seq'::regclass),
    "code_id" INTEGER NOT NULL,
    "code_value" VARCHAR(100) DEFAULT NULL::character varying,
    "order_position" INTEGER NOT NULL DEFAULT 0,
    CONSTRAINT "m_code_value_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_code_value_code_id_code_value_key" UNIQUE ("code_id", "code_value"),
    CONSTRAINT "m_code_value_code_id_key" UNIQUE ("code_id")
);

-- Table: m_currency
CREATE TABLE "fineract_bk_mifostenant-default"."m_currency" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_currency_id_seq'::regclass),
    "code" VARCHAR(3) NOT NULL,
    "decimal_places" SMALLINT NOT NULL,
    "display_symbol" VARCHAR(10) DEFAULT NULL::character varying,
    "name" VARCHAR(50) NOT NULL,
    "internationalized_name_code" VARCHAR(50) NOT NULL,
    CONSTRAINT "m_currency_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_currency_code_key" UNIQUE ("code")
);

-- Table: m_document
CREATE TABLE "fineract_bk_mifostenant-default"."m_document" (
    "id" INTEGER NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_document_id_seq'::regclass),
    "parent_entity_type" VARCHAR(50) NOT NULL,
    "parent_entity_id" INTEGER NOT NULL DEFAULT 0,
    "name" VARCHAR(250) NOT NULL,
    "file_name" VARCHAR(250) NOT NULL,
    "size" INTEGER DEFAULT 0,
    "type" VARCHAR(50) DEFAULT NULL::character varying,
    "description" VARCHAR(1000) DEFAULT NULL::character varying,
    "location" VARCHAR(500) NOT NULL DEFAULT '0'::character varying,
    CONSTRAINT "m_document_pkey" PRIMARY KEY ("id")
);

-- Table: m_fund
CREATE TABLE "fineract_bk_mifostenant-default"."m_fund" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_fund_id_seq'::regclass),
    "name" VARCHAR(255) DEFAULT NULL::character varying,
    "external_id" VARCHAR(100) DEFAULT NULL::character varying,
    CONSTRAINT "m_fund_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_fund_external_id_key" UNIQUE ("external_id"),
    CONSTRAINT "m_fund_name_key" UNIQUE ("name")
);

-- Table: m_group
CREATE TABLE "fineract_bk_mifostenant-default"."m_group" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_group_id_seq'::regclass),
    "office_id" BIGINT NOT NULL,
    "staff_id" BIGINT,
    "parent_id" BIGINT,
    "level_Id" INTEGER NOT NULL,
    "hierarchy" VARCHAR(100) DEFAULT NULL::character varying,
    "name" VARCHAR(100) NOT NULL,
    "external_id" VARCHAR(100) DEFAULT NULL::character varying,
    "is_deleted" SMALLINT NOT NULL DEFAULT '0'::smallint,
    CONSTRAINT "m_group_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_group_external_id_level_Id_key" UNIQUE ("external_id", "level_Id"),
    CONSTRAINT "m_group_level_Id_key" UNIQUE ("level_Id"),
    CONSTRAINT "m_group_name_level_Id_key" UNIQUE ("name", "level_Id"),
    CONSTRAINT "m_group_office_id_key" UNIQUE ("office_id"),
    CONSTRAINT "m_group_parent_id_key" UNIQUE ("parent_id"),
    CONSTRAINT "m_group_staff_id_key" UNIQUE ("staff_id")
);

-- Table: m_group_client
CREATE TABLE "fineract_bk_mifostenant-default"."m_group_client" (
    "group_id" BIGINT NOT NULL,
    "client_id" BIGINT NOT NULL,
    CONSTRAINT "m_group_client_pkey" PRIMARY KEY ("group_id", "client_id"),
    CONSTRAINT "m_group_client_client_id_key" UNIQUE ("client_id")
);

-- Table: m_group_level
CREATE TABLE "fineract_bk_mifostenant-default"."m_group_level" (
    "id" INTEGER NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_group_level_id_seq'::regclass),
    "parent_id" INTEGER,
    "super_parent" SMALLINT NOT NULL,
    "level_name" VARCHAR(100) NOT NULL,
    "recursable" SMALLINT NOT NULL,
    "can_have_clients" SMALLINT NOT NULL,
    CONSTRAINT "m_group_level_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_group_level_parent_id_key" UNIQUE ("parent_id")
);

-- Table: m_guarantor
CREATE TABLE "fineract_bk_mifostenant-default"."m_guarantor" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_guarantor_id_seq'::regclass),
    "loan_id" BIGINT NOT NULL,
    "type_enum" SMALLINT NOT NULL,
    "entity_id" BIGINT,
    "firstname" VARCHAR(50) DEFAULT NULL::character varying,
    "lastname" VARCHAR(50) DEFAULT NULL::character varying,
    "dob" DATE,
    "address_line_1" VARCHAR(500) DEFAULT NULL::character varying,
    "address_line_2" VARCHAR(500) DEFAULT NULL::character varying,
    "city" VARCHAR(50) DEFAULT NULL::character varying,
    "state" VARCHAR(50) DEFAULT NULL::character varying,
    "country" VARCHAR(50) DEFAULT NULL::character varying,
    "zip" VARCHAR(20) DEFAULT NULL::character varying,
    "house_phone_number" VARCHAR(20) DEFAULT NULL::character varying,
    "mobile_number" VARCHAR(20) DEFAULT NULL::character varying,
    "comment" VARCHAR(500) DEFAULT NULL::character varying,
    CONSTRAINT "m_guarantor_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_guarantor_loan_id_key" UNIQUE ("loan_id")
);

-- Table: m_loan
CREATE TABLE "fineract_bk_mifostenant-default"."m_loan" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_loan_id_seq'::regclass),
    "account_no" VARCHAR(20) NOT NULL,
    "external_id" VARCHAR(100) DEFAULT NULL::character varying,
    "client_id" BIGINT,
    "group_id" BIGINT,
    "product_id" BIGINT,
    "fund_id" BIGINT,
    "loan_officer_id" BIGINT,
    "loanpurpose_cv_id" INTEGER,
    "loan_status_id" SMALLINT NOT NULL,
    "currency_code" VARCHAR(3) NOT NULL,
    "currency_digits" SMALLINT NOT NULL,
    "principal_amount" NUMERIC(19,6) NOT NULL,
    "arrearstolerance_amount" NUMERIC(19,6) DEFAULT NULL::numeric,
    "nominal_interest_rate_per_period" NUMERIC(19,6) NOT NULL,
    "interest_period_frequency_enum" SMALLINT NOT NULL,
    "annual_nominal_interest_rate" NUMERIC(19,6) NOT NULL,
    "interest_method_enum" SMALLINT NOT NULL,
    "interest_calculated_in_period_enum" SMALLINT NOT NULL DEFAULT '1'::smallint,
    "term_frequency" SMALLINT NOT NULL DEFAULT '0'::smallint,
    "term_period_frequency_enum" SMALLINT NOT NULL DEFAULT '2'::smallint,
    "repay_every" SMALLINT NOT NULL,
    "repayment_period_frequency_enum" SMALLINT NOT NULL,
    "number_of_repayments" SMALLINT NOT NULL,
    "amortization_method_enum" SMALLINT NOT NULL,
    "submittedon_date" DATE,
    "submittedon_userid" BIGINT,
    "approvedon_date" DATE,
    "approvedon_userid" BIGINT,
    "expected_disbursedon_date" DATE,
    "expected_firstrepaymenton_date" DATE,
    "interest_calculated_from_date" DATE,
    "disbursedon_date" DATE,
    "disbursedon_userid" BIGINT,
    "expected_maturedon_date" DATE,
    "maturedon_date" DATE,
    "closedon_date" DATE,
    "closedon_userid" BIGINT,
    "total_charges_due_at_disbursement_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "principal_disbursed_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "principal_repaid_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "principal_writtenoff_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "principal_outstanding_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "interest_charged_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "interest_repaid_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "interest_waived_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "interest_writtenoff_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "interest_outstanding_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "fee_charges_charged_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "fee_charges_repaid_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "fee_charges_waived_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "fee_charges_writtenoff_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "fee_charges_outstanding_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "penalty_charges_charged_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "penalty_charges_repaid_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "penalty_charges_waived_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "penalty_charges_writtenoff_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "penalty_charges_outstanding_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "total_expected_repayment_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "total_repayment_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "total_expected_costofloan_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "total_costofloan_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "total_waived_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "total_writtenoff_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "total_outstanding_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "rejectedon_date" DATE,
    "rejectedon_userid" BIGINT,
    "rescheduledon_date" DATE,
    "withdrawnon_date" DATE,
    "withdrawnon_userid" BIGINT,
    "writtenoffon_date" DATE,
    "loan_transaction_strategy_id" BIGINT,
    CONSTRAINT "m_loan_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_loan_account_no_key" UNIQUE ("account_no"),
    CONSTRAINT "m_loan_approvedon_userid_key" UNIQUE ("approvedon_userid"),
    CONSTRAINT "m_loan_client_id_key" UNIQUE ("client_id"),
    CONSTRAINT "m_loan_closedon_userid_key" UNIQUE ("closedon_userid"),
    CONSTRAINT "m_loan_disbursedon_userid_key" UNIQUE ("disbursedon_userid"),
    CONSTRAINT "m_loan_external_id_key" UNIQUE ("external_id"),
    CONSTRAINT "m_loan_fund_id_key" UNIQUE ("fund_id"),
    CONSTRAINT "m_loan_group_id_key" UNIQUE ("group_id"),
    CONSTRAINT "m_loan_loan_officer_id_key" UNIQUE ("loan_officer_id"),
    CONSTRAINT "m_loan_loanpurpose_cv_id_key" UNIQUE ("loanpurpose_cv_id"),
    CONSTRAINT "m_loan_product_id_key" UNIQUE ("product_id"),
    CONSTRAINT "m_loan_rejectedon_userid_key" UNIQUE ("rejectedon_userid"),
    CONSTRAINT "m_loan_submittedon_userid_key" UNIQUE ("submittedon_userid"),
    CONSTRAINT "m_loan_withdrawnon_userid_key" UNIQUE ("withdrawnon_userid")
);

-- Table: m_loan_arrears_aging
CREATE TABLE "fineract_bk_mifostenant-default"."m_loan_arrears_aging" (
    "loan_id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_loan_arrears_aging_loan_id_seq'::regclass),
    "principal_overdue_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "interest_overdue_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "fee_charges_overdue_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "penalty_charges_overdue_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "total_overdue_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "overdue_since_date_derived" DATE,
    CONSTRAINT "m_loan_arrears_aging_pkey" PRIMARY KEY ("loan_id")
);

-- Table: m_loan_charge
CREATE TABLE "fineract_bk_mifostenant-default"."m_loan_charge" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_loan_charge_id_seq'::regclass),
    "loan_id" BIGINT NOT NULL,
    "charge_id" BIGINT NOT NULL,
    "is_penalty" SMALLINT NOT NULL DEFAULT '0'::smallint,
    "charge_time_enum" SMALLINT NOT NULL,
    "due_for_collection_as_of_date" DATE,
    "charge_calculation_enum" SMALLINT NOT NULL,
    "calculation_percentage" NUMERIC(19,6) DEFAULT NULL::numeric,
    "calculation_on_amount" NUMERIC(19,6) DEFAULT NULL::numeric,
    "amount" NUMERIC(19,6) NOT NULL,
    "amount_paid_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "amount_waived_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "amount_writtenoff_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "amount_outstanding_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    "is_paid_derived" SMALLINT NOT NULL DEFAULT '0'::smallint,
    "waived" SMALLINT NOT NULL DEFAULT '0'::smallint,
    CONSTRAINT "m_loan_charge_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_loan_charge_charge_id_key" UNIQUE ("charge_id"),
    CONSTRAINT "m_loan_charge_loan_id_key" UNIQUE ("loan_id")
);

-- Table: m_loan_collateral
CREATE TABLE "fineract_bk_mifostenant-default"."m_loan_collateral" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_loan_collateral_id_seq'::regclass),
    "loan_id" BIGINT NOT NULL,
    "type_cv_id" INTEGER NOT NULL,
    "description" VARCHAR(500) DEFAULT NULL::character varying,
    CONSTRAINT "m_loan_collateral_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_loan_collateral_loan_id_key" UNIQUE ("loan_id"),
    CONSTRAINT "m_loan_collateral_type_cv_id_key" UNIQUE ("type_cv_id")
);

-- Table: m_loan_officer_assignment_history
CREATE TABLE "fineract_bk_mifostenant-default"."m_loan_officer_assignment_history" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_loan_officer_assignment_history_id_seq'::regclass),
    "loan_id" BIGINT NOT NULL,
    "loan_officer_id" BIGINT,
    "start_date" DATE NOT NULL,
    "end_date" DATE,
    "createdby_id" BIGINT,
    "created_date" TIMESTAMP,
    "lastmodified_date" TIMESTAMP,
    "lastmodifiedby_id" BIGINT,
    CONSTRAINT "m_loan_officer_assignment_history_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_loan_officer_assignment_history_loan_id_key" UNIQUE ("loan_id"),
    CONSTRAINT "m_loan_officer_assignment_history_loan_officer_id_key" UNIQUE ("loan_officer_id")
);

-- Table: m_loan_repayment_schedule
CREATE TABLE "fineract_bk_mifostenant-default"."m_loan_repayment_schedule" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_loan_repayment_schedule_id_seq'::regclass),
    "loan_id" BIGINT NOT NULL,
    "fromdate" DATE,
    "duedate" DATE NOT NULL,
    "installment" SMALLINT NOT NULL,
    "principal_amount" NUMERIC(19,6) DEFAULT NULL::numeric,
    "principal_completed_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "principal_writtenoff_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "interest_amount" NUMERIC(19,6) DEFAULT NULL::numeric,
    "interest_completed_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "interest_writtenoff_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "fee_charges_amount" NUMERIC(19,6) DEFAULT NULL::numeric,
    "fee_charges_completed_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "fee_charges_writtenoff_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "fee_charges_waived_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "penalty_charges_amount" NUMERIC(19,6) DEFAULT NULL::numeric,
    "penalty_charges_completed_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "penalty_charges_writtenoff_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "penalty_charges_waived_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "completed_derived" BOOLEAN NOT NULL,
    "createdby_id" BIGINT,
    "created_date" TIMESTAMP,
    "lastmodified_date" TIMESTAMP,
    "lastmodifiedby_id" BIGINT,
    "interest_waived_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    CONSTRAINT "m_loan_repayment_schedule_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_loan_repayment_schedule_loan_id_key" UNIQUE ("loan_id")
);

-- Table: m_loan_transaction
CREATE TABLE "fineract_bk_mifostenant-default"."m_loan_transaction" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_loan_transaction_id_seq'::regclass),
    "loan_id" BIGINT NOT NULL,
    "is_reversed" SMALLINT NOT NULL,
    "transaction_type_enum" SMALLINT NOT NULL,
    "transaction_date" DATE NOT NULL,
    "amount" NUMERIC(19,6) NOT NULL,
    "principal_portion_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "interest_portion_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "fee_charges_portion_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "penalty_charges_portion_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    CONSTRAINT "m_loan_transaction_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_loan_transaction_loan_id_key" UNIQUE ("loan_id")
);

-- Table: m_note
CREATE TABLE "fineract_bk_mifostenant-default"."m_note" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_note_id_seq'::regclass),
    "client_id" BIGINT,
    "group_id" BIGINT,
    "loan_id" BIGINT,
    "loan_transaction_id" BIGINT,
    "note_type_enum" SMALLINT NOT NULL,
    "note" VARCHAR(1000) DEFAULT NULL::character varying,
    "created_date" TIMESTAMP,
    "createdby_id" BIGINT,
    "lastmodified_date" TIMESTAMP,
    "lastmodifiedby_id" BIGINT,
    CONSTRAINT "m_note_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_note_client_id_key" UNIQUE ("client_id"),
    CONSTRAINT "m_note_createdby_id_key" UNIQUE ("createdby_id"),
    CONSTRAINT "m_note_group_id_key" UNIQUE ("group_id"),
    CONSTRAINT "m_note_lastmodifiedby_id_key" UNIQUE ("lastmodifiedby_id"),
    CONSTRAINT "m_note_loan_id_key" UNIQUE ("loan_id"),
    CONSTRAINT "m_note_loan_transaction_id_key" UNIQUE ("loan_transaction_id")
);

-- Table: m_office
CREATE TABLE "fineract_bk_mifostenant-default"."m_office" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_office_id_seq'::regclass),
    "parent_id" BIGINT,
    "hierarchy" VARCHAR(100) DEFAULT NULL::character varying,
    "external_id" VARCHAR(100) DEFAULT NULL::character varying,
    "name" VARCHAR(50) NOT NULL,
    "opening_date" DATE NOT NULL,
    CONSTRAINT "m_office_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_office_external_id_key" UNIQUE ("external_id"),
    CONSTRAINT "m_office_name_key" UNIQUE ("name"),
    CONSTRAINT "m_office_parent_id_key" UNIQUE ("parent_id")
);

-- Table: m_office_transaction
CREATE TABLE "fineract_bk_mifostenant-default"."m_office_transaction" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_office_transaction_id_seq'::regclass),
    "from_office_id" BIGINT,
    "to_office_id" BIGINT,
    "currency_code" VARCHAR(3) NOT NULL,
    "currency_digits" INTEGER NOT NULL,
    "transaction_amount" NUMERIC(19,6) NOT NULL,
    "transaction_date" DATE NOT NULL,
    "description" VARCHAR(100) DEFAULT NULL::character varying,
    CONSTRAINT "m_office_transaction_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_office_transaction_from_office_id_key" UNIQUE ("from_office_id"),
    CONSTRAINT "m_office_transaction_to_office_id_key" UNIQUE ("to_office_id")
);

-- Table: m_organisation_currency
CREATE TABLE "fineract_bk_mifostenant-default"."m_organisation_currency" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_organisation_currency_id_seq'::regclass),
    "code" VARCHAR(3) NOT NULL,
    "decimal_places" SMALLINT NOT NULL,
    "name" VARCHAR(50) NOT NULL,
    "display_symbol" VARCHAR(10) DEFAULT NULL::character varying,
    "internationalized_name_code" VARCHAR(50) NOT NULL,
    CONSTRAINT "m_organisation_currency_pkey" PRIMARY KEY ("id")
);

-- Table: m_permission
CREATE TABLE "fineract_bk_mifostenant-default"."m_permission" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_permission_id_seq'::regclass),
    "grouping" VARCHAR(45) DEFAULT NULL::character varying,
    "code" VARCHAR(100) NOT NULL,
    "entity_name" VARCHAR(100) DEFAULT NULL::character varying,
    "action_name" VARCHAR(100) DEFAULT NULL::character varying,
    "can_maker_checker" SMALLINT NOT NULL DEFAULT '1'::smallint,
    CONSTRAINT "m_permission_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_permission_code_key" UNIQUE ("code")
);

-- Table: m_portfolio_command_source
CREATE TABLE "fineract_bk_mifostenant-default"."m_portfolio_command_source" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_portfolio_command_source_id_seq'::regclass),
    "action_name" VARCHAR(50) NOT NULL,
    "entity_name" VARCHAR(50) NOT NULL,
    "office_id" BIGINT,
    "group_id" BIGINT,
    "client_id" BIGINT,
    "loan_id" BIGINT,
    "api_get_url" VARCHAR(100) NOT NULL,
    "resource_id" BIGINT,
    "subresource_id" BIGINT,
    "command_as_json" TEXT NOT NULL,
    "maker_id" BIGINT NOT NULL,
    "made_on_date" TIMESTAMP NOT NULL,
    "checker_id" BIGINT,
    "checked_on_date" TIMESTAMP,
    "status" SMALLINT NOT NULL,
    CONSTRAINT "m_portfolio_command_source_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_portfolio_command_source_action_name_key" UNIQUE ("action_name"),
    CONSTRAINT "m_portfolio_command_source_checked_on_date_key" UNIQUE ("checked_on_date"),
    CONSTRAINT "m_portfolio_command_source_checker_id_key" UNIQUE ("checker_id"),
    CONSTRAINT "m_portfolio_command_source_entity_name_resource_id_key" UNIQUE ("entity_name", "resource_id"),
    CONSTRAINT "m_portfolio_command_source_made_on_date_key" UNIQUE ("made_on_date"),
    CONSTRAINT "m_portfolio_command_source_maker_id_key" UNIQUE ("maker_id"),
    CONSTRAINT "m_portfolio_command_source_office_id_key" UNIQUE ("office_id"),
    CONSTRAINT "m_portfolio_command_source_status_key" UNIQUE ("status")
);

-- Table: m_product_loan
CREATE TABLE "fineract_bk_mifostenant-default"."m_product_loan" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_product_loan_id_seq'::regclass),
    "currency_code" VARCHAR(3) NOT NULL,
    "currency_digits" SMALLINT NOT NULL,
    "principal_amount" NUMERIC(19,6) NOT NULL,
    "arrearstolerance_amount" NUMERIC(19,6) DEFAULT NULL::numeric,
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(500) DEFAULT NULL::character varying,
    "fund_id" BIGINT,
    "nominal_interest_rate_per_period" NUMERIC(19,6) NOT NULL,
    "interest_period_frequency_enum" SMALLINT NOT NULL,
    "annual_nominal_interest_rate" NUMERIC(19,6) NOT NULL,
    "interest_method_enum" SMALLINT NOT NULL,
    "interest_calculated_in_period_enum" SMALLINT NOT NULL DEFAULT '1'::smallint,
    "repay_every" SMALLINT NOT NULL,
    "repayment_period_frequency_enum" SMALLINT NOT NULL,
    "number_of_repayments" SMALLINT NOT NULL,
    "amortization_method_enum" SMALLINT NOT NULL,
    "accounting_type" SMALLINT NOT NULL,
    "loan_transaction_strategy_id" BIGINT,
    CONSTRAINT "m_product_loan_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_product_loan_fund_id_key" UNIQUE ("fund_id"),
    CONSTRAINT "m_product_loan_name_key" UNIQUE ("name")
);

-- Table: m_product_loan_charge
CREATE TABLE "fineract_bk_mifostenant-default"."m_product_loan_charge" (
    "product_loan_id" BIGINT NOT NULL,
    "charge_id" BIGINT NOT NULL,
    CONSTRAINT "m_product_loan_charge_pkey" PRIMARY KEY ("product_loan_id", "charge_id"),
    CONSTRAINT "m_product_loan_charge_charge_id_key" UNIQUE ("charge_id")
);

-- Table: m_role
CREATE TABLE "fineract_bk_mifostenant-default"."m_role" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_role_id_seq'::regclass),
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(500) NOT NULL,
    CONSTRAINT "m_role_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_role_name_key" UNIQUE ("name")
);

-- Table: m_role_permission
CREATE TABLE "fineract_bk_mifostenant-default"."m_role_permission" (
    "role_id" BIGINT NOT NULL,
    "permission_id" BIGINT NOT NULL,
    CONSTRAINT "m_role_permission_pkey" PRIMARY KEY ("role_id", "permission_id"),
    CONSTRAINT "m_role_permission_permission_id_key" UNIQUE ("permission_id"),
    CONSTRAINT "m_role_permission_role_id_key" UNIQUE ("role_id")
);

-- Table: m_savings_account
CREATE TABLE "fineract_bk_mifostenant-default"."m_savings_account" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_savings_account_id_seq'::regclass),
    "account_no" VARCHAR(20) NOT NULL,
    "external_id" VARCHAR(100) DEFAULT NULL::character varying,
    "client_id" BIGINT,
    "group_id" BIGINT,
    "product_id" BIGINT,
    "status_enum" SMALLINT NOT NULL DEFAULT '300'::smallint,
    "activation_date" DATE,
    "currency_code" VARCHAR(3) NOT NULL,
    "currency_digits" SMALLINT NOT NULL,
    "nominal_interest_rate_per_period" NUMERIC(19,6) NOT NULL,
    "nominal_interest_rate_period_frequency_enum" SMALLINT NOT NULL,
    "annual_nominal_interest_rate" NUMERIC(19,6) NOT NULL,
    "min_required_opening_balance" NUMERIC(19,6) DEFAULT NULL::numeric,
    "lockin_period_frequency" NUMERIC(19,6) DEFAULT NULL::numeric,
    "lockin_period_frequency_enum" SMALLINT,
    "lockedin_until_date_derived" DATE,
    "total_deposits_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "total_withdrawals_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "total_interest_posted_derived" NUMERIC(19,6) DEFAULT NULL::numeric,
    "account_balance_derived" NUMERIC(19,6) NOT NULL DEFAULT 0.000000,
    CONSTRAINT "m_savings_account_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_savings_account_account_no_key" UNIQUE ("account_no"),
    CONSTRAINT "m_savings_account_client_id_key" UNIQUE ("client_id"),
    CONSTRAINT "m_savings_account_external_id_key" UNIQUE ("external_id"),
    CONSTRAINT "m_savings_account_group_id_key" UNIQUE ("group_id"),
    CONSTRAINT "m_savings_account_product_id_key" UNIQUE ("product_id")
);

-- Table: m_savings_account_transaction
CREATE TABLE "fineract_bk_mifostenant-default"."m_savings_account_transaction" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_savings_account_transaction_id_seq'::regclass),
    "savings_account_id" BIGINT NOT NULL,
    "transaction_type_enum" SMALLINT NOT NULL,
    "transaction_date" DATE NOT NULL,
    "amount" NUMERIC(19,6) NOT NULL,
    "is_reversed" SMALLINT NOT NULL,
    CONSTRAINT "m_savings_account_transaction_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_savings_account_transaction_savings_account_id_key" UNIQUE ("savings_account_id")
);

-- Table: m_savings_product
CREATE TABLE "fineract_bk_mifostenant-default"."m_savings_product" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_savings_product_id_seq'::regclass),
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(500) NOT NULL,
    "currency_code" VARCHAR(3) NOT NULL,
    "currency_digits" SMALLINT NOT NULL,
    "nominal_interest_rate_per_period" NUMERIC(19,6) NOT NULL,
    "nominal_interest_rate_period_frequency_enum" SMALLINT NOT NULL,
    "min_required_opening_balance" NUMERIC(19,6) DEFAULT NULL::numeric,
    "lockin_period_frequency" NUMERIC(19,6) DEFAULT NULL::numeric,
    "lockin_period_frequency_enum" SMALLINT,
    CONSTRAINT "m_savings_product_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_savings_product_name_key" UNIQUE ("name")
);

-- Table: m_staff
CREATE TABLE "fineract_bk_mifostenant-default"."m_staff" (
    "id" BIGINT NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".m_staff_id_seq'::regclass),
    "is_loan_officer" SMALLINT NOT NULL DEFAULT '0'::smallint,
    "office_id" BIGINT,
    "firstname" VARCHAR(50) DEFAULT NULL::character varying,
    "lastname" VARCHAR(50) DEFAULT NULL::character varying,
    "display_name" VARCHAR(100) NOT NULL,
    CONSTRAINT "m_staff_pkey" PRIMARY KEY ("id"),
    CONSTRAINT "m_staff_display_name_key" UNIQUE ("display_name"),
    CONSTRAINT "m_staff_office_id_key" UNIQUE ("office_id")
);

-- Table: r_enum_value
CREATE TABLE "fineract_bk_mifostenant-default"."r_enum_value" (
    "enum_name" VARCHAR(100) NOT NULL,
    "enum_id" INTEGER NOT NULL,
    "enum_message_property" VARCHAR(100) NOT NULL,
    "enum_value" VARCHAR(100) NOT NULL,
    CONSTRAINT "r_enum_value_pkey" PRIMARY KEY ("enum_name", "enum_id"),
    CONSTRAINT "r_enum_value_enum_name_enum_message_property_key" UNIQUE ("enum_name", "enum_message_property"),
    CONSTRAINT "r_enum_value_enum_name_enum_value_key" UNIQUE ("enum_name", "enum_value")
);

-- Table: rpt_sequence
CREATE TABLE "fineract_bk_mifostenant-default"."rpt_sequence" (
    "id" INTEGER NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".rpt_sequence_id_seq'::regclass),
    CONSTRAINT "rpt_sequence_pkey" PRIMARY KEY ("id")
);

-- Table: stretchy_parameter
CREATE TABLE "fineract_bk_mifostenant-default"."stretchy_parameter" (
    "parameter_id" INTEGER NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".stretchy_parameter_parameter_id_seq'::regclass),
    "parameter_name" VARCHAR(45) NOT NULL,
    "parameter_variable" VARCHAR(45) DEFAULT NULL::character varying,
    "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::character varying,
    "selectOne" VARCHAR(1) DEFAULT NULL::character varying,
    "selectAll" VARCHAR(1) DEFAULT NULL::character varying,
    "parameter_sql" TEXT,
    "parent_parameter_id" INTEGER,
    CONSTRAINT "stretchy_parameter_pkey" PRIMARY KEY ("parameter_id"),
    CONSTRAINT "stretchy_parameter_parameter_name_key" UNIQUE ("parameter_name"),
    CONSTRAINT "stretchy_parameter_parent_parameter_id_key" UNIQUE ("parent_parameter_id")
);

-- Table: stretchy_report
CREATE TABLE "fineract_bk_mifostenant-default"."stretchy_report" (
    "report_id" INTEGER NOT NULL DEFAULT nextval('"fineract_bk_mifostenant-default".stretchy_report_report_id_seq'::regclass),
    "report_name" VARCHAR(100) NOT NULL,
    "report_type" VARCHAR(20) NOT NULL,
    "report_subtype" VARCHAR(20) DEFAULT NULL::character varying,
    "report_category" VARCHAR(45) DEFAULT NULL::character varying,
    "report_sql" TEXT,
    "description" TEXT,
    "core_report" SMALLINT DEFAULT '0'::smallint,
    "use_report" SMALLINT DEFAULT '0'::smallint,
    CONSTRAINT "stretchy_report_pkey" PRIMARY KEY ("report_id"),
    CONSTRAINT "stretchy_report_report_name_key" UNIQUE ("report_name")
);

-- Table: stretchy_report_parameter
CREATE TABLE "fineract_bk_mifostenant-default"."stretchy_report_parameter" (
    "report_id" INTEGER NOT NULL,
    "parameter_id" INTEGER NOT NULL,
    "report_parameter_name" VARCHAR(45) DEFAULT NULL::character varying,
    CONSTRAINT "stretchy_report_parameter_pkey" PRIMARY KEY ("report_id", "parameter_id"),
    CONSTRAINT "stretchy_report_parameter_report_id_report_parameter_name_key" UNIQUE ("report_id", "report_parameter_name")
);

-- Table: x_registered_table
CREATE TABLE "fineract_bk_mifostenant-default"."x_registered_table" (
    "registered_table_name" VARCHAR(50) NOT NULL,
    "application_table_name" VARCHAR(50) NOT NULL,
    CONSTRAINT "x_registered_table_pkey" PRIMARY KEY ("registered_table_name")
);

-- Foreign Keys
ALTER TABLE "fineract_bk_mifostenant-default"."acc_gl_account" ADD CONSTRAINT "fk_acc_gl_account_0" FOREIGN KEY ("parent_id") REFERENCES "fineract_bk_mifostenant-default"."acc_gl_account" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."acc_gl_closure" ADD CONSTRAINT "fk_acc_gl_closure_0" FOREIGN KEY ("createdby_id") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."acc_gl_closure" ADD CONSTRAINT "fk_acc_gl_closure_1" FOREIGN KEY ("lastmodifiedby_id") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."acc_gl_closure" ADD CONSTRAINT "fk_acc_gl_closure_2" FOREIGN KEY ("office_id") REFERENCES "fineract_bk_mifostenant-default"."m_office" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."acc_gl_journal_entry" ADD CONSTRAINT "fk_acc_gl_journal_entry_0" FOREIGN KEY ("account_id") REFERENCES "fineract_bk_mifostenant-default"."acc_gl_account" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."acc_gl_journal_entry" ADD CONSTRAINT "fk_acc_gl_journal_entry_1" FOREIGN KEY ("reversal_id") REFERENCES "fineract_bk_mifostenant-default"."acc_gl_journal_entry" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."acc_gl_journal_entry" ADD CONSTRAINT "fk_acc_gl_journal_entry_2" FOREIGN KEY ("createdby_id") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."acc_gl_journal_entry" ADD CONSTRAINT "fk_acc_gl_journal_entry_3" FOREIGN KEY ("lastmodifiedby_id") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."acc_gl_journal_entry" ADD CONSTRAINT "fk_acc_gl_journal_entry_4" FOREIGN KEY ("office_id") REFERENCES "fineract_bk_mifostenant-default"."m_office" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."extra_client_details" ADD CONSTRAINT "fk_extra_client_details_0" FOREIGN KEY ("client_id") REFERENCES "fineract_bk_mifostenant-default"."m_client" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."extra_family_details" ADD CONSTRAINT "fk_extra_family_details_0" FOREIGN KEY ("client_id") REFERENCES "fineract_bk_mifostenant-default"."m_client" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."extra_loan_details" ADD CONSTRAINT "fk_extra_loan_details_0" FOREIGN KEY ("loan_id") REFERENCES "fineract_bk_mifostenant-default"."m_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_appuser" ADD CONSTRAINT "fk_m_appuser_0" FOREIGN KEY ("office_id") REFERENCES "fineract_bk_mifostenant-default"."m_office" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_appuser_role" ADD CONSTRAINT "fk_m_appuser_role_0" FOREIGN KEY ("role_id") REFERENCES "fineract_bk_mifostenant-default"."m_role" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_appuser_role" ADD CONSTRAINT "fk_m_appuser_role_1" FOREIGN KEY ("appuser_id") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_calendar_instance" ADD CONSTRAINT "fk_m_calendar_instance_0" FOREIGN KEY ("calendar_id") REFERENCES "fineract_bk_mifostenant-default"."m_calendar" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_client" ADD CONSTRAINT "fk_m_client_0" FOREIGN KEY ("office_id") REFERENCES "fineract_bk_mifostenant-default"."m_office" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_client_identifier" ADD CONSTRAINT "fk_m_client_identifier_0" FOREIGN KEY ("client_id") REFERENCES "fineract_bk_mifostenant-default"."m_client" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_client_identifier" ADD CONSTRAINT "fk_m_client_identifier_1" FOREIGN KEY ("document_type_id") REFERENCES "fineract_bk_mifostenant-default"."m_code_value" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_code_value" ADD CONSTRAINT "fk_m_code_value_0" FOREIGN KEY ("code_id") REFERENCES "fineract_bk_mifostenant-default"."m_code" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_group" ADD CONSTRAINT "fk_m_group_0" FOREIGN KEY ("office_id") REFERENCES "fineract_bk_mifostenant-default"."m_office" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_group" ADD CONSTRAINT "fk_m_group_1" FOREIGN KEY ("parent_id") REFERENCES "fineract_bk_mifostenant-default"."m_group" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_group" ADD CONSTRAINT "fk_m_group_2" FOREIGN KEY ("level_Id") REFERENCES "fineract_bk_mifostenant-default"."m_group_level" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_group" ADD CONSTRAINT "fk_m_group_3" FOREIGN KEY ("staff_id") REFERENCES "fineract_bk_mifostenant-default"."m_staff" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_group_client" ADD CONSTRAINT "fk_m_group_client_0" FOREIGN KEY ("group_id") REFERENCES "fineract_bk_mifostenant-default"."m_group" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_group_client" ADD CONSTRAINT "fk_m_group_client_1" FOREIGN KEY ("client_id") REFERENCES "fineract_bk_mifostenant-default"."m_client" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_group_level" ADD CONSTRAINT "fk_m_group_level_0" FOREIGN KEY ("parent_id") REFERENCES "fineract_bk_mifostenant-default"."m_group_level" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_guarantor" ADD CONSTRAINT "fk_m_guarantor_0" FOREIGN KEY ("loan_id") REFERENCES "fineract_bk_mifostenant-default"."m_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_0" FOREIGN KEY ("fund_id") REFERENCES "fineract_bk_mifostenant-default"."m_fund" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_1" FOREIGN KEY ("client_id") REFERENCES "fineract_bk_mifostenant-default"."m_client" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_10" FOREIGN KEY ("withdrawnon_userid") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_11" FOREIGN KEY ("group_id") REFERENCES "fineract_bk_mifostenant-default"."m_group" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_2" FOREIGN KEY ("product_id") REFERENCES "fineract_bk_mifostenant-default"."m_product_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_3" FOREIGN KEY ("approvedon_userid") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_4" FOREIGN KEY ("closedon_userid") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_5" FOREIGN KEY ("disbursedon_userid") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_6" FOREIGN KEY ("loanpurpose_cv_id") REFERENCES "fineract_bk_mifostenant-default"."m_code_value" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_7" FOREIGN KEY ("loan_officer_id") REFERENCES "fineract_bk_mifostenant-default"."m_staff" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_8" FOREIGN KEY ("rejectedon_userid") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan" ADD CONSTRAINT "fk_m_loan_9" FOREIGN KEY ("submittedon_userid") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan_arrears_aging" ADD CONSTRAINT "fk_m_loan_arrears_aging_0" FOREIGN KEY ("loan_id") REFERENCES "fineract_bk_mifostenant-default"."m_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan_charge" ADD CONSTRAINT "fk_m_loan_charge_0" FOREIGN KEY ("charge_id") REFERENCES "fineract_bk_mifostenant-default"."m_charge" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan_charge" ADD CONSTRAINT "fk_m_loan_charge_1" FOREIGN KEY ("loan_id") REFERENCES "fineract_bk_mifostenant-default"."m_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan_collateral" ADD CONSTRAINT "fk_m_loan_collateral_0" FOREIGN KEY ("loan_id") REFERENCES "fineract_bk_mifostenant-default"."m_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan_collateral" ADD CONSTRAINT "fk_m_loan_collateral_1" FOREIGN KEY ("type_cv_id") REFERENCES "fineract_bk_mifostenant-default"."m_code_value" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan_officer_assignment_history" ADD CONSTRAINT "fk_m_loan_officer_assignment_history_0" FOREIGN KEY ("loan_id") REFERENCES "fineract_bk_mifostenant-default"."m_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan_officer_assignment_history" ADD CONSTRAINT "fk_m_loan_officer_assignment_history_1" FOREIGN KEY ("loan_officer_id") REFERENCES "fineract_bk_mifostenant-default"."m_staff" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan_repayment_schedule" ADD CONSTRAINT "fk_m_loan_repayment_schedule_0" FOREIGN KEY ("loan_id") REFERENCES "fineract_bk_mifostenant-default"."m_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_loan_transaction" ADD CONSTRAINT "fk_m_loan_transaction_0" FOREIGN KEY ("loan_id") REFERENCES "fineract_bk_mifostenant-default"."m_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_note" ADD CONSTRAINT "fk_m_note_0" FOREIGN KEY ("loan_transaction_id") REFERENCES "fineract_bk_mifostenant-default"."m_loan_transaction" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_note" ADD CONSTRAINT "fk_m_note_1" FOREIGN KEY ("loan_id") REFERENCES "fineract_bk_mifostenant-default"."m_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_note" ADD CONSTRAINT "fk_m_note_2" FOREIGN KEY ("createdby_id") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_note" ADD CONSTRAINT "fk_m_note_3" FOREIGN KEY ("client_id") REFERENCES "fineract_bk_mifostenant-default"."m_client" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_note" ADD CONSTRAINT "fk_m_note_4" FOREIGN KEY ("group_id") REFERENCES "fineract_bk_mifostenant-default"."m_group" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_note" ADD CONSTRAINT "fk_m_note_5" FOREIGN KEY ("lastmodifiedby_id") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_office" ADD CONSTRAINT "fk_m_office_0" FOREIGN KEY ("parent_id") REFERENCES "fineract_bk_mifostenant-default"."m_office" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_office_transaction" ADD CONSTRAINT "fk_m_office_transaction_0" FOREIGN KEY ("from_office_id") REFERENCES "fineract_bk_mifostenant-default"."m_office" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_office_transaction" ADD CONSTRAINT "fk_m_office_transaction_1" FOREIGN KEY ("to_office_id") REFERENCES "fineract_bk_mifostenant-default"."m_office" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_portfolio_command_source" ADD CONSTRAINT "fk_m_portfolio_command_source_0" FOREIGN KEY ("checker_id") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_portfolio_command_source" ADD CONSTRAINT "fk_m_portfolio_command_source_1" FOREIGN KEY ("maker_id") REFERENCES "fineract_bk_mifostenant-default"."m_appuser" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_product_loan" ADD CONSTRAINT "fk_m_product_loan_0" FOREIGN KEY ("fund_id") REFERENCES "fineract_bk_mifostenant-default"."m_fund" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_product_loan_charge" ADD CONSTRAINT "fk_m_product_loan_charge_0" FOREIGN KEY ("charge_id") REFERENCES "fineract_bk_mifostenant-default"."m_charge" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_product_loan_charge" ADD CONSTRAINT "fk_m_product_loan_charge_1" FOREIGN KEY ("product_loan_id") REFERENCES "fineract_bk_mifostenant-default"."m_product_loan" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_role_permission" ADD CONSTRAINT "fk_m_role_permission_0" FOREIGN KEY ("permission_id") REFERENCES "fineract_bk_mifostenant-default"."m_permission" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_role_permission" ADD CONSTRAINT "fk_m_role_permission_1" FOREIGN KEY ("role_id") REFERENCES "fineract_bk_mifostenant-default"."m_role" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_savings_account" ADD CONSTRAINT "fk_m_savings_account_0" FOREIGN KEY ("client_id") REFERENCES "fineract_bk_mifostenant-default"."m_client" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_savings_account" ADD CONSTRAINT "fk_m_savings_account_1" FOREIGN KEY ("group_id") REFERENCES "fineract_bk_mifostenant-default"."m_group" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_savings_account" ADD CONSTRAINT "fk_m_savings_account_2" FOREIGN KEY ("product_id") REFERENCES "fineract_bk_mifostenant-default"."m_savings_product" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_savings_account_transaction" ADD CONSTRAINT "fk_m_savings_account_transaction_0" FOREIGN KEY ("savings_account_id") REFERENCES "fineract_bk_mifostenant-default"."m_savings_account" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."m_staff" ADD CONSTRAINT "fk_m_staff_0" FOREIGN KEY ("office_id") REFERENCES "fineract_bk_mifostenant-default"."m_office" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "fineract_bk_mifostenant-default"."stretchy_parameter" ADD CONSTRAINT "fk_stretchy_parameter_0" FOREIGN KEY ("parent_parameter_id") REFERENCES "fineract_bk_mifostenant-default"."stretchy_parameter" ("parameter_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
