Clear document mappings on soft delete

Document soft delete cleared generated-document references but left
control, risk, and measure junction rows pointing at deleted documents.
That blocked risk deletion and made unlinkRisk fail when the document
was already gone.

Remove entity mappings in SoftDelete and BulkSoftDelete, drop mappings
before deleting a risk, tolerate missing documents when unlinking, and
backfill orphaned junction rows for soft-deleted documents.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
Cursor Agent
2026-07-29 15:01:37 +00:00
committed by Bryan Frimin
parent c6ad0154b9
commit f451e94c0b
7 changed files with 229 additions and 35 deletions

View File

@@ -108,6 +108,33 @@ WHERE
return err
}
func (rp RiskDocument) DeleteByRiskID(
ctx context.Context,
conn pg.Tx,
scope Scoper,
riskID gid.GID,
) error {
q := `
DELETE
FROM
risks_documents
WHERE
%s
AND risk_id = @risk_id;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"risk_id": riskID,
}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
return err
}
func (rp RiskDocument) DeleteByDocumentIDs(
ctx context.Context,
conn pg.Tx,