KRYSTALM7 opened a new pull request, #47:
URL: https://github.com/apache/fineract-loan-origination/pull/47

   # Description
   
   This pull request fixes multiple database schema inconsistencies between the 
existing Flyway migrations (V1–V6) and the current JPA entity model. These 
changes ensure the database schema accurately reflects the application domain 
model, improve data integrity, and add missing indexes for frequently executed 
queries.
   
   **Closes #46**
   
   ## Summary
   
   * Added the missing `version` column to `loan_application` to support JPA 
optimistic locking (`@Version`) and prevent schema validation failures when 
running with `ddl-auto: validate`.
   * Added a `UNIQUE` constraint on `applicant_profile.application_id` to 
enforce the intended one-to-one relationship at the database level and 
eliminate potential race conditions.
   * Added a `UNIQUE` constraint on `credit_score.application_id` to guarantee 
a single persisted credit score per loan application.
   * Added an index on `required_document.application_id` to improve 
foreign-key lookup performance.
   * Added a composite index on `(fineract_client_id, tenant_id)` in 
`applicant_profile` to optimize customer-scoped application lookups.
   
   ## Migration Note
   
   Since existing Flyway migration files have been modified, any previously 
initialized development database must be dropped and recreated before running 
the application. Flyway validates migration checksums and will reject modified 
migrations that have already been applied.
   
   ## Issue Link
   
   [FINERACT-2442](https://issues.apache.org/jira/browse/FINERACT-2442)
   
   ## Checklist
   
   * [x] I have read the Apache Fineract Contributing Guidelines.
   * [x] My pull request is linked to the correct JIRA ticket number.
   * [x] My commit message follows the `FINERACT-<issue-no> - <issue-desc>` 
format.
   * [x] I have manually verified the database migration changes.
   * [x] I have verified that the project builds successfully.
   
   ## Method of Testing
   
   ### Manual Verification
   
   * Recreated the local PostgreSQL database and executed the updated Flyway 
migrations.
   * Verified the application starts successfully with `ddl-auto: validate` 
enabled.
   * Confirmed the `loan_application.version` column is present and mapped 
correctly.
   * Verified duplicate `applicant_profile` rows for the same `application_id` 
are rejected by the database.
   * Verified duplicate `credit_score` rows for the same `application_id` are 
rejected by the database.
   * Confirmed the new indexes were created successfully.
   
   ### Build Command
   
   ```bash
   ./mvnw clean verify
   ```
   
   ## Notes
   
   This pull request aligns the database schema with the current JPA entity 
model by adding missing constraints, indexes, and optimistic locking support. 
It improves data integrity and query performance without changing the 
application's business logic or REST API behavior.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to