Fix duplicate assessments
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -22,6 +22,7 @@ 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"
|
||||
@@ -361,6 +362,13 @@ INSERT INTO processing_activity_data_protection_impact_assessments (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "processing_activity_dpias_processing_activity_id_snapshot_id_uniq" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert data protection impact assessment: %w", err)
|
||||
}
|
||||
|
||||
|
||||
33
pkg/coredata/migrations/20260209T125649Z.sql
Normal file
33
pkg/coredata/migrations/20260209T125649Z.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
DELETE FROM processing_activity_data_protection_impact_assessments
|
||||
WHERE id IN (
|
||||
SELECT id
|
||||
FROM (
|
||||
SELECT id,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY processing_activity_id, COALESCE(snapshot_id, '')
|
||||
ORDER BY updated_at DESC
|
||||
) AS rn
|
||||
FROM processing_activity_data_protection_impact_assessments
|
||||
) t
|
||||
WHERE rn > 1
|
||||
);
|
||||
|
||||
DELETE FROM processing_activity_transfer_impact_assessments
|
||||
WHERE id IN (
|
||||
SELECT id
|
||||
FROM (
|
||||
SELECT id,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY processing_activity_id, COALESCE(snapshot_id, '')
|
||||
ORDER BY updated_at DESC
|
||||
) AS rn
|
||||
FROM processing_activity_transfer_impact_assessments
|
||||
) t
|
||||
WHERE rn > 1
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX processing_activity_dpias_processing_activity_id_snapshot_id_uniq
|
||||
ON processing_activity_data_protection_impact_assessments (processing_activity_id, COALESCE(snapshot_id, ''));
|
||||
|
||||
CREATE UNIQUE INDEX processing_activity_tias_processing_activity_id_snapshot_id_uniq
|
||||
ON processing_activity_transfer_impact_assessments (processing_activity_id, COALESCE(snapshot_id, ''));
|
||||
@@ -22,6 +22,7 @@ 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"
|
||||
@@ -359,6 +360,13 @@ INSERT INTO processing_activity_transfer_impact_assessments (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "processing_activity_tias_processing_activity_id_snapshot_id_uniq" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert transfer impact assessment: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -5141,7 +5141,12 @@ func (r *mutationResolver) CreateDataProtectionImpactAssessment(ctx context.Cont
|
||||
|
||||
dpia, err := prb.DataProtectionImpactAssessments.Create(ctx, &req)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot create data protection impact assessment: %w", err))
|
||||
if errors.Is(err, coredata.ErrResourceAlreadyExists) {
|
||||
return nil, gqlutils.Conflict(ctx, err)
|
||||
}
|
||||
|
||||
r.logger.ErrorCtx(ctx, "cannot create data protection impact assessment", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
return &types.CreateDataProtectionImpactAssessmentPayload{
|
||||
@@ -5213,7 +5218,12 @@ func (r *mutationResolver) CreateTransferImpactAssessment(ctx context.Context, i
|
||||
|
||||
tia, err := prb.TransferImpactAssessments.Create(ctx, &req)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot create transfer impact assessment: %w", err))
|
||||
if errors.Is(err, coredata.ErrResourceAlreadyExists) {
|
||||
return nil, gqlutils.Conflict(ctx, err)
|
||||
}
|
||||
|
||||
r.logger.ErrorCtx(ctx, "cannot create transfer impact assessment", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
return &types.CreateTransferImpactAssessmentPayload{
|
||||
|
||||
Reference in New Issue
Block a user