Skip to content

fix: drop broken loan_events FK from loan_disputes migration#1289

Open
SharifIbrahimDev wants to merge 1 commit into
LabsCrypt:mainfrom
SharifIbrahimDev:fix/loan-disputes-fk
Open

fix: drop broken loan_events FK from loan_disputes migration#1289
SharifIbrahimDev wants to merge 1 commit into
LabsCrypt:mainfrom
SharifIbrahimDev:fix/loan-disputes-fk

Conversation

@SharifIbrahimDev

Copy link
Copy Markdown

Closes #1191

What does this PR do?

This PR resolves a database migration failure where loan_disputes attempted to create a foreign key referencing loan_events(loan_id). Because loan_events.loan_id lacks a total unique constraint and acts as an append-only event log (and is later renamed to a view via contract_events), PostgreSQL rejects the foreign key.

Description

  • Dropped DB-level FK: Removed the REFERENCES loan_events(loan_id) constraint from the loan_disputes schema migration. The schema now relies on application-level validation for loan_id associations, which is already handled seamlessly by the existing robust controllers and indexed events flow.
  • Clean Application: This change confirms that the loan_disputes migration will apply cleanly, unaffected by the loan_events -> contract_events rename or the view creation that happens in subsequent migrations.
  • Integration Test: Added a dedicated integration test (loanDisputesSchema.test.ts) that asserts an actual dispute record can be cleanly inserted against the real database schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] loan_disputes foreign key references loan_events(loan_id), which has no total UNIQUE constraint

1 participant