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:
Émile Ré
2026-05-20 10:14:45 +04:00
parent f3cc159f1f
commit 34c25c2727
8 changed files with 47 additions and 23 deletions

View File

@@ -1219,8 +1219,13 @@ VALUES (
_, err := conn.Exec(ctx, q, args)
if err != nil {
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok && pgErr.Code == "23505" && pgErr.ConstraintName == "idx_profiles_identity_id_organization_id" {
return ErrResourceAlreadyExists
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok && pgErr.Code == "23505" {
switch pgErr.ConstraintName {
case "idx_profiles_identity_id_organization_id",
"idx_profiles_external_id_organization_id",
"idx_profiles_user_name_organization_id":
return ErrResourceAlreadyExists
}
}
return fmt.Errorf("cannot insert profile: %w", err)