Refine PgError constraint checks and document PK rule
Remove dead 23505 checks on single-GID primary keys (oauth2_consent, risk_assessment, risk_assessment_scenario, risk_assessment_scope). Add missing constraints to membership_profile and statement_of_applicability. Document composite-PK vs GID-PK rule in cursor rules and contrib guide. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"go.gearno.de/kit/pg"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
"go.probo.inc/probo/pkg/page"
|
||||
@@ -191,9 +190,6 @@ VALUES (@id, @tenant_id, @organization_id, @name, @description, @created_at, @up
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok && pgErr.Code == "23505" && pgErr.ConstraintName == "risk_assessments_pkey" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
return fmt.Errorf("cannot insert risk assessment: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user