Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0
Why this matters
migrations/1784000000014_add-loan-disputes.js:9 declares loan_id INTEGER NOT NULL REFERENCES loan_events(loan_id). loan_events.loan_id (migrations/1771691269866_loan-events-schema.js:16) is nullable with only a plain index; the only unique constraints touching loan_id are composite (loan_id,event_type,ledger) or PARTIAL (WHERE event_type=LoanApproved), none of which a FK can target. Postgres rejects this with there is no unique constraint matching given keys for referenced table loan_events. The model is also wrong: loan_events is an append-only event log with many rows per loan_id.
Acceptance criteria
Files to touch
backend/migrations/1784000000014_add-loan-disputes.js
backend/migrations/1771691269866_loan-events-schema.js
Out of scope
- Dispute resolution business logic
Why this matters
migrations/1784000000014_add-loan-disputes.js:9 declares loan_id INTEGER NOT NULL REFERENCES loan_events(loan_id). loan_events.loan_id (migrations/1771691269866_loan-events-schema.js:16) is nullable with only a plain index; the only unique constraints touching loan_id are composite (loan_id,event_type,ledger) or PARTIAL (WHERE event_type=LoanApproved), none of which a FK can target. Postgres rejects this with there is no unique constraint matching given keys for referenced table loan_events. The model is also wrong: loan_events is an append-only event log with many rows per loan_id.
Acceptance criteria
Files to touch
backend/migrations/1784000000014_add-loan-disputes.jsbackend/migrations/1771691269866_loan-events-schema.jsOut of scope