Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(review): drop the removed purge fence from review run creation (#21305)
rebelicea7e9acffb83e
diff --git a/backend/store/review_run.go b/backend/store/review_run.goindex 313039086d..73454fc963 100644--- a/backend/store/review_run.go+++ b/backend/store/review_run.go@@ -43,11 +43,8 @@ type ReviewRunMessage struct {// completion transaction is fenced on the old attempt and will match zero// rows.//-// Lifecycle policy: the slot requires an active project. The transaction-// takes the project purge fence and then the project row lock (the sheet-// creation shape), so it serializes against project purge; the INSERT reads-// the issue row itself, so a missing issue returns NotFound instead of a-// foreign-key error.+// The slot requires an active project; the INSERT reads the issue row itself,+// so a missing issue returns NotFound instead of a foreign-key error.func (s *Store) CreateReviewRun(ctx context.Context, projectID string, issueUID int64, reviewType string) (*ReviewRunMessage, error) {tx, err := s.GetDB().BeginTx(ctx, nil)if err != nil {@@ -55,10 +52,7 @@ func (s *Store) CreateReviewRun(ctx context.Context, projectID string, issueUID}defer tx.Rollback()- if err := acquireProjectPurgeLock(ctx, tx, projectID); err != nil {- return nil, err- }- if err := lockActiveProject(ctx, tx, projectID); err != nil {+ if err := requireActiveProject(ctx, tx, projectID); err != nil {return nil, err}diff --git a/backend/store/review_run_lock_order_test.go b/backend/store/review_run_lock_order_test.godeleted file mode 100644index 9dec41ad3f..0000000000--- a/backend/store/review_run_lock_order_test.go+++ /dev/null@@ -1,46 +0,0 @@-package store_test--import (- "context"- "strings"- "testing"-- "github.com/stretchr/testify/require"-- "github.com/bytebase/bytebase/backend/common"- "github.com/bytebase/bytebase/backend/store"-)--func createReviewRunInProjectA(ctx context.Context, s *store.Store) error {- _, err := s.CreateReviewRun(ctx, "project-a", 101, store.ReviewRunTypeRule)- return err-}--const reviewRunLockOrderSeedSQL = `- INSERT INTO issue (id, creator, project, name, status, type)- VALUES (101, '[email protected]', 'project-a', 'Issue A', 'OPEN', 'DATABASE_CHANGE');- INSERT INTO review_run (project, issue_id, type, status)- VALUES ('project-a', 101, 'RULE', 'DONE');-`--// Purge first: project deletion wedges inside its review_run delete while-// CreateReviewRun queues behind the project purge fence. The create must end in-// a clean NotFound once the purge wins — no deadlock, no FK failure — and the-// purge itself must succeed against the seeded slot row.-func TestCreateReviewRunDoesNotDeadlockWithProjectDeletion(t *testing.T) {- err := runWithConcurrentProjectDeletion(t, reviewRunLockOrderSeedSQL, "review_run", 9906, createReviewRunInProjectA)- require.Equal(t, common.NotFound, common.ErrorCode(err))- require.NotContains(t, strings.ToLower(err.Error()), "foreign key",- "the create must reject the purged project cleanly, not with an FK failure")-}--// Writer first: CreateReviewRun holds the purge fence and waits on the project-// row; project deletion queues behind the fence. The create must reject the-// soft-deleted project with NotFound, and the purge must then complete.-func TestCreateReviewRunRejectsDeletedProjectDuringProjectDeletion(t *testing.T) {- operationErr, deleteErr := runWithCreationBeforeProjectDeletion(t, reviewRunLockOrderSeedSQL, "review_run", createReviewRunInProjectA)- require.NoError(t, deleteErr)- require.Equal(t, common.NotFound, common.ErrorCode(operationErr))- require.NotContains(t, strings.ToLower(operationErr.Error()), "foreign key",- "the create must reject the deleted project cleanly, not with an FK failure")-}diff --git a/backend/store/review_run_test.go b/backend/store/review_run_test.goindex ab62ba898e..ac80f8b32f 100644--- a/backend/store/review_run_test.go+++ b/backend/store/review_run_test.go@@ -14,7 +14,7 @@ import (// TestReviewRunStoreLifecycle walks the slot through reset, claim, supersede,// fenced completion, and heartbeat reaping against a real PostgreSQL.func TestReviewRunStoreLifecycle(t *testing.T) {- fixture := newProjectDeletionLockOrderFixture(t, `+ fixture := newStorePostgresFixture(t, `INSERT INTO issue (id, creator, project, name, status, type)VALUES (201, '[email protected]', 'default', 'Issue Default', 'OPEN', 'DATABASE_CHANGE');`)