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:
@@ -227,8 +227,10 @@ VALUES (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "statements_of_applicability_document_id_key" {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok && pgErr.Code == "23505" {
|
||||
switch pgErr.ConstraintName {
|
||||
case "statements_of_applicability_document_id_key",
|
||||
"states_of_applicability_name_organization_id_uniq":
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
@@ -267,8 +269,10 @@ WHERE
|
||||
|
||||
result, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "statements_of_applicability_document_id_key" {
|
||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok && pgErr.Code == "23505" {
|
||||
switch pgErr.ConstraintName {
|
||||
case "statements_of_applicability_document_id_key",
|
||||
"states_of_applicability_name_organization_id_uniq":
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user