Skip to content

Add unique constraint on loan_events to prevent duplicate indexing #721

@ogazboiz

Description

@ogazboiz

Join our community: https://t.me/+DOylgFv1jyJlNzM0

Description

The event indexer can insert duplicate rows into loan_events if it re-processes the same ledger range (e.g., on restart). There is no unique constraint to prevent this.

What Needs to Happen

  • Add a unique constraint on (loan_id, event_type, ledger) in loan_events
  • Use INSERT ... ON CONFLICT DO NOTHING in the indexer insert query
  • Add a migration for the constraint

Files

  • backend/migrations/
  • backend/src/services/eventIndexer.ts

Acceptance Criteria

  • Duplicate events cannot be inserted
  • Indexer handles conflicts gracefully on restart
  • Tests verify idempotent indexing

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendIssues related to backend developmentdatabaseDatabase related issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions