diff --git a/modules/events/internal/store/capture.go b/modules/events/internal/store/capture.go index 1c8d01bf1..f20f27c54 100644 --- a/modules/events/internal/store/capture.go +++ b/modules/events/internal/store/capture.go @@ -19,7 +19,10 @@ var ErrInUse = errors.New("in use") // ErrExists means a row with that name already exists. var ErrExists = errors.New("already exists") +// Postgres reports a delete blocked by ON DELETE RESTRICT as 23001 and a +// reference to a missing row as 23503. const ( + restrictViolation = "23001" foreignKeyViolation = "23503" uniqueViolation = "23505" ) @@ -29,7 +32,7 @@ const ( func classify(err error) error { if pqErr, ok := errors.AsType[*pgconn.PgError](err); ok { switch pqErr.Code { - case foreignKeyViolation: + case restrictViolation, foreignKeyViolation: return fmt.Errorf("%w: %s", ErrInUse, pqErr.Detail) case uniqueViolation: return ErrExists