Skip to content

feat(store): org projects search skips soft-deleted rows - #1943

Merged
AmanGIT07 merged 4 commits into
mainfrom
soft-delete-org-projects-reads
Sep 24, 2026
Merged

AmanGIT07 merged 4 commits into
mainfrom
soft-delete-org-projects-reads

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Second of the org view repositories. Follows #1939.

Summary

The org projects search leaves out soft-deleted policies, projects, and users. The member count and the user ids count live rows only.

Changes

  • The base query starts from fromLive(policies) and adds live(projects) and live(users).
  • New docker-backed suite org_projects_repository_pg_test.go: seeds a soft-deleted project, a project whose only policy is soft-deleted, a soft-deleted user, and a soft-deleted policy, then checks the listing and the member counts.
  • postgres_test.go gains the shared execSQL and scalarSQL runners. They are the same helpers as in feat(store): org users search skips soft-deleted rows #1939, copied so both branches merge cleanly. The copy goes away on rebase once feat(store): org users search skips soft-deleted rows #1939 lands.

Technical Details

The search had no soft-delete filter at all. The joins are inner, so a project with no live policy drops out of the listing, the same way a project with no policies is absent today.

Frontier does not set deleted_at on policies yet, so the listing returns the same rows as before.

Test Plan

  • go test -run 'TestOrgProjectsRepository' ./internal/store/postgres/ passes (unit tests and the new suite)
  • The new suite fails on main
  • golangci-lint run ./internal/store/postgres/... reports no issues
  • End to end against a local server through AdminService/SearchOrganizationProjects and AdminService/ExportOrganizationProjects. An org, four projects and three members were created through the public RPCs, then deleted_at was set by SQL. The same scenarios ran against main on the same database, with only the binary swapped.
# Scenario This branch main
1 Baseline before any soft delete: four projects, one with four members PASS PASS
2 Soft-deleted project is not listed PASS FAIL
3 Project whose every policy is soft-deleted is not listed PASS FAIL
4 Only live projects are listed PASS FAIL
5 member_count drops the soft-deleted user and the soft-deleted policy PASS FAIL
6 user_ids holds only the live members PASS FAIL
7 The soft-deleted user appears in no project PASS FAIL
8 Filter name eq the soft-deleted project returns nothing PASS FAIL
9 Filter name eq a live project still returns it PASS PASS
10 Text search returns live projects only PASS FAIL
11 Export CSV lists live projects only PASS FAIL

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.

The search reads policies, projects, and users through the live-row
helpers. Frontier does not set deleted_at on policies yet, so results
do not change today.
…-deleted rows

Seeds a soft-deleted project, a project whose only policy is soft-deleted,
a soft-deleted user, and a soft-deleted policy, then checks the listing
and the member counts. Brings in the shared SQL runners.
@vercel

vercel Bot commented Sep 22, 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 23, 2026 11:05am UTC

@coderabbitai

coderabbitai Bot commented Sep 22, 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: 8fa86af7-2ea8-4ee9-ab71-bddec2bd0a10

📥 Commits

Reviewing files that changed from the base of the PR and between 6fdae90 and 6c44e80.

📒 Files selected for processing (2)
  • internal/store/postgres/org_projects_repository.go
  • internal/store/postgres/org_projects_repository_pg_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/store/postgres/org_projects_repository.go
  • internal/store/postgres/org_projects_repository_pg_test.go

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Organization project searches now exclude soft-deleted projects, policies, and users, so deleted records no longer appear in results.
    • Member counts and member IDs now include only users from live records.
    • Project-related aggregations now reflect live records only, providing more accurate search results and membership information.

Walkthrough

The org-project query now excludes soft-deleted policies, projects, and users. Unit SQL expectations and a PostgreSQL integration suite verify filtering and live membership counts.

Changes

Org-project live-row filtering

Layer / File(s) Summary
Apply live-row query filters
internal/store/postgres/org_projects_repository.go, internal/store/postgres/org_projects_repository_test.go
The base query uses live policies and filters joined projects and users by deleted_at IS NULL. Expected SQL strings reflect the added predicates and placeholder positions.
Validate live-row repository results
internal/store/postgres/org_projects_repository_pg_test.go, internal/store/postgres/postgres_test.go
The PostgreSQL suite seeds live and soft-deleted records, runs repository searches, and verifies excluded records and live-only member counts. Shared SQL helpers support fixture setup and assertions.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 6c44e

The updated filtering behavior is covered by the supplied repository and PostgreSQL test evidence; no merge-blocking risk remains.

🚥 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.

@coveralls

coveralls commented Sep 22, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 35852502356

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.9%) to 51.641%

Details

  • Coverage increased (+0.9%) from the base build.
  • Patch coverage: 9 of 9 lines across 1 file are fully covered (100%).
  • 90 coverage regressions across 7 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

90 previously-covered lines in 7 files lost coverage.

File Lines Losing Coverage Coverage
core/authenticate/authenticators.go 24 61.54%
internal/store/postgres/serviceuser_repository.go 21 49.43%
internal/api/v1beta1connect/policy.go 14 84.42%
internal/store/postgres/domain_repository.go 14 51.05%
internal/store/postgres/role_repository.go 7 73.42%
internal/store/postgres/serviceuser_credential_repository.go 6 61.7%
internal/store/postgres/group_repository.go 4 76.13%

Coverage Stats

Coverage Status
Relevant Lines: 41124
Covered Lines: 21237
Line Coverage: 51.64%
Coverage Strength: 16.76 hits per line

💛 - Coveralls

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: 98da7162-96e6-423f-910e-6e345ce4be4d

📥 Commits

Reviewing files that changed from the base of the PR and between 64aa400 and 6fdae90.

📒 Files selected for processing (4)
  • internal/store/postgres/org_projects_repository.go
  • internal/store/postgres/org_projects_repository_pg_test.go
  • internal/store/postgres/org_projects_repository_test.go
  • internal/store/postgres/postgres_test.go

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.

The org filter and both live filters go to a single Where call. The
generated SQL is unchanged.
… missing

The case filters by name and requires one row, instead of asserting
inside a loop that runs zero times when the project is absent.
@AmanGIT07
AmanGIT07 merged commit a2ba3a2 into main Sep 24, 2026
8 checks passed
@AmanGIT07
AmanGIT07 deleted the soft-delete-org-projects-reads branch September 24, 2026 08:07

This branch was successfully deployed

1 active deployment
Preview — 6c44e80e Deployed Sep 23, 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