Skip to content

feat(db): add soft-delete pattern for core entities - #1816

Merged
github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
faith3310:fix/issue-1800-soft-delete-core-entities
Oct 17, 2026
Merged

github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
faith3310:fix/issue-1800-soft-delete-core-entities

Conversation

@faith3310

Copy link
Copy Markdown
Contributor

Summary

Resolves #1800

Adds deleted_at TIMESTAMPTZ columns to 7 core entity tables with partial indexes for active/deleted filtering, a SoftDeleteHelper utility for consistent query building, and a filterActive function for patching existing queries.

Changes

  • Create db/migrations/011_soft_delete_core_entities.sql: adds deleted_at to subscriptions, transactions, users, merchants, loyalty, payment_methods, plans. Includes partial indexes and -- @down rollback.
  • Create backend/shared/db/softDelete.ts: SoftDeleteHelper class, SOFT_DELETE_HELPERS map, filterActive() function
  • Create backend/shared/db/__tests__/softDelete.test.ts: 16 test cases

Acceptance Criteria

  • Consistent filtering — filterActive() and SoftDeleteHelper provide uniform deleted_at IS NULL filtering
  • Restore path — restoreSql() sets deleted_at back to NULL
  • Tested — 16 test cases

Add deleted_at TIMESTAMPTZ columns to 7 core entity tables with partial
indexes for active/deleted filtering, a SoftDeleteHelper utility for
consistent query building, and a filterActive function for patching
existing queries.

Changes:
- Create db/migrations/011_soft_delete_core_entities.sql: adds deleted_at
  to subscriptions, transactions, users, merchants, loyalty,
  payment_methods, plans. Includes partial indexes for active and deleted
  rows, and -- @down rollback.
- Create backend/shared/db/softDelete.ts: SoftDeleteHelper class with
  activeFilter, deletedFilter, softDeleteSql, restoreSql, purgeSql,
  findDeletedSql. SOFT_DELETE_HELPERS map for all tables. filterActive()
  function to patch SELECT queries.
- Create backend/shared/db/__tests__/softDelete.test.ts: 16 test cases

Acceptance criteria:
- [x] Consistent filtering — filterActive() and SoftDeleteHelper provide
      uniform deleted_at IS NULL filtering across all repositories
- [x] Restore path — restoreSql() sets deleted_at back to NULL
- [x] Tested — 16 test cases covering all helpers and filterActive edge cases
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@faith3310 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@github-actions
github-actions Bot merged commit d930a0a into Smartdevs17:main Oct 17, 2026
13 of 30 checks passed
@faith3310
faith3310 deployed to security-review October 17, 2026 11:04 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
security-review — 2ba7bc27 Deployed Oct 17, 2026 by faith3310 via Security Dashboard #1366
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.

Add soft-delete pattern for core entities

2 participants