Skip to content

feat(store): add a helper that marks rows as deleted - #1959

Merged
AmanGIT07 merged 1 commit into
mainfrom
soft-delete-helper
Sep 29, 2026
Merged

AmanGIT07 merged 1 commit into
mainfrom
soft-delete-helper

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Summary

Adds softDelete(table) to internal/store/postgres/postgres.go, next to live and fromLive. It builds the update that marks the live rows of a table as deleted.

Changes

  • softDelete(table) builds UPDATE <table> SET deleted_at = now() WHERE <table>.deleted_at IS NULL.
  • A caller adds its own filter with Where. goqu joins it to the live filter with AND.
  • A row that is already deleted is not touched, so it keeps its first delete time.
  • New postgres_internal_test.go checks the exact SQL the helper builds, alone and with a caller's filter. It is in package postgres because the helper is unexported, and postgres_test.go is in package postgres_test.

Technical Details

No repository calls the helper yet. The soft delete changes that follow will use it.

Test Plan

  • go test ./internal/store/postgres/ passes
  • The new test fails when the live filter is left out of the helper
  • golangci-lint run ./internal/store/postgres/... reports no issues

SQL Safety

  • Values flow through ? placeholders, goqu.Ex{}, or goqu.Record{} — never fmt.Sprintf or + building a query that gets executed.
  • ToSQL() callers capture and forward params (query, params, err := stmt.ToSQL(); db.…Context(ctx, …, query, params...)). Never query, _, err := ….
  • No ? placeholders inside single-quoted SQL literals in goqu.L.
  • No new //nolint:forbidigo or // #nosec G20x annotations.

softDelete(table) builds the update that sets deleted_at on the live rows of
a table. Rows that are already deleted are skipped, so they keep their first
delete time. Callers add their own filter with Where.
@vercel

vercel Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
frontier Ready Ready Preview Sep 29, 2026 9:05am UTC

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: raystack/frontier/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 473c724f-d8ea-4062-8b26-3e09c8efca69

📥 Commits

Reviewing files that changed from the base of the PR and between af7634f and 5376f46.

📒 Files selected for processing (2)
  • internal/store/postgres/postgres.go
  • internal/store/postgres/postgres_internal_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Soft-deleted records now retain their original deletion time when deletion is attempted again; only records not already marked as deleted are updated.

Walkthrough

The PostgreSQL store adds a softDelete helper that sets deleted_at to the current time for live rows. Tests check the generated SQL and parameters, including when a caller-supplied ID filter is present.

Changes

Postgres soft delete

Layer / File(s) Summary
Soft-delete query and validation
internal/store/postgres/postgres.go, internal/store/postgres/postgres_internal_test.go
softDelete updates rows only when deleted_at is null. Table-driven tests check the generated SQL, parameters, and combination of the live-row condition with an ID filter.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Suggested reviewers: whoabhisheksah

Merge Risk: ⚪ Minimal · up to 5376f

No merge-blocking issue is identified; the change is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 5376f

The helper is not yet used by production code, so this change does not show a new reachable deletion path. Future callers will need to restrict which rows they delete.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — If a future caller executes the dataset without an additional filter, the generated predicate would select every live row in its chosen table. The observed test does not execute that statement, and no production caller is established for this PR.

Trust Boundaries and Controls

  • observed — The SQL predicate controls deletion state, not caller identity or row ownership. The tested ID restriction is supplied by the caller rather than enforced by the helper.

Hardening Proposals

  • proposed — When production callers are added, verify authorization and asset scope before constructing the update, and exercise retry, affected-row, and failure behavior at the execution boundary.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AmanGIT07
AmanGIT07 merged commit 60668f8 into main Sep 29, 2026
8 checks passed
@AmanGIT07
AmanGIT07 deleted the soft-delete-helper branch September 29, 2026 09:09
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 36546808030

Coverage increased (+0.004%) to 52.704%

Details

  • Coverage increased (+0.004%) from the base build.
  • Patch coverage: 3 of 3 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 41255
Covered Lines: 21743
Line Coverage: 52.7%
Coverage Strength: 16.91 hits per line

💛 - Coveralls

This branch was successfully deployed

1 active deployment
Preview — 5376f465 Deployed Sep 29, 2026 by vercel[bot]
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.

3 participants