Skip to content

fix: purge the project or group row when its create rolls back - #2066

Open
0xABCD01 wants to merge 1 commit into
raystack:mainfrom
0xABCD01:fix/2009-purge-on-create-rollback
Open

0xABCD01 wants to merge 1 commit into
raystack:mainfrom
0xABCD01:fix/2009-purge-on-create-rollback

Conversation

@0xABCD01

Copy link
Copy Markdown

Summary

When project.Service.Create or group.Service.Create fails after the row is inserted (the SpiceDB link or the owner-policy step fails), the rollback called the repository Delete. Since #2007 (projects) and #2016 (groups) that delete is soft, so a failed create left a row with deleted_at set behind instead of nothing.

The rollback now purges the row: a new Purge method on both repositories removes it outright. This is the first fix option named in #2009.

Changes

  • core/project, core/group: Repository gains Purge(ctx, id); both Service.Create rollbacks call Purge instead of Delete.
  • internal/store/postgres: ProjectRepository.Purge runs a real DELETE ... RETURNING in a transaction and still writes the project.deleted audit record, so the project.created / project.deleted audit pair is recorded exactly as before. GroupRepository.Purge runs a real DELETE ... RETURNING and mirrors Delete's error mapping (ErrNotExist, ErrInvalidUUID); the group repository writes no audit record on delete today, and Purge keeps that.
  • Mocks for both repositories regenerated in the same mockery style (hand-extended, mockery is not installed here).
  • Service tests: the existing rollback cases now expect Purge instead of Delete.

Delete itself and the DeleteModel paths are unchanged — user-facing deletes stay soft.

Test Plan

  • Manual testing completed
  • Build and type checking passes
  • go build ./... passes; go vet passes on core/project, core/group, internal/store/postgres.
  • go test ./core/project/ ./core/group/ passes. Verified fail-before/pass-after: with the two service rollback calls reverted to Delete, the updated rollback tests fail (the mock reports the unexpected soft-delete call and the unmet Purge expectation) in both packages; with this change they pass.
  • The internal/store/postgres suites need a Docker Postgres (dockertest) and could not run in my sandbox (no Docker); Purge there follows the same query/transaction shape as the existing Delete methods, and upstream CI runs those suites.

SQL Safety (if your PR touches *_repository.go or goqu.*)

  • 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 (use make_interval(hours => ?)-style functions instead).
  • Any //nolint:forbidigo or // #nosec G20x annotation has a one-line justification on the same line that a reviewer can verify. (None added.)

Fixes #2009

@vercel

vercel Bot commented Nov 25, 2026

Copy link
Copy Markdown

@0xABCD01 is attempting to deploy a commit to the Raystack Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 27 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4e33f29 and 387c745.

Files selected for processing: 10

  • core/group/group.go
  • core/group/mocks/repository.go
  • core/group/service.go
  • core/group/service_test.go
  • core/project/mocks/repository.go
  • core/project/project.go
  • core/project/service.go
  • core/project/service_test.go
  • internal/store/postgres/group_repository.go
  • internal/store/postgres/project_repository.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

This branch has not been deployed

No deployments
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.

A failed project or group create leaves a deleted row behind

1 participant