Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ export const up = (pgm) => {
};

/**
* Keep rollback non-destructive because several indexes above may already
* exist from prior migrations with shared names.
*
* @param pgm {import('node-pg-migrate').MigrationBuilder}
* @returns {void}
*/
export const down = () => {};
export const down = (pgm) => {
pgm.sql(`DROP INDEX IF EXISTS idx_loan_events_created_at;`);
pgm.sql(`DROP INDEX IF EXISTS idx_loan_events_loan_id_event_type;`);
pgm.sql(`DROP INDEX IF EXISTS idx_loan_events_event_type;`);
pgm.sql(`DROP INDEX IF EXISTS idx_loan_events_borrower;`);
};
8 changes: 8 additions & 0 deletions pr_body_1193.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Closes #1193

### What does this PR do?
This PR implements the missing `down()` function in the `1788000000018_add-loan-events-missing-indexes.js` migration file, which previously leaked four database indexes on rollback.

### Description
- **Clean Rollbacks:** Replaced the empty `down = () => {}` with explicit `DROP INDEX IF EXISTS` statements for all four indexes (`idx_loan_events_borrower`, `idx_loan_events_event_type`, `idx_loan_events_loan_id_event_type`, and `idx_loan_events_created_at`) created in the `up()` function.
- **Idempotency:** Ensures that rolling back and re-applying migrations works flawlessly without index collision errors.
Loading