Move pending signature requests on minor publish

When a new minor version is published, still-REQUESTED signature requests
on the previous version now move onto the newly published version, keeping
the same signature row so the notification schedule (count and last-notified
time) is preserved. SIGNED signatures are left untouched.

Signed-off-by: Sacha Al Himdani <sacha@probo.com>
This commit is contained in:
Sacha Al Himdani
2026-06-24 10:51:32 +02:00
parent 45b434dd99
commit 612e9cbc22
3 changed files with 151 additions and 0 deletions

View File

@@ -728,6 +728,47 @@ WHERE
return nil
}
func (pvss *DocumentVersionSignatures) MoveRequestedToVersionWithinMajor(
ctx context.Context,
conn pg.Tx,
scope Scoper,
targetVersionID gid.GID,
) error {
q := `
UPDATE document_version_signatures
SET
document_version_id = @target_version_id,
updated_at = @now
WHERE
%s
AND state = @state
AND document_version_id <> @target_version_id
AND document_version_id IN (
SELECT dv.id
FROM document_versions dv
INNER JOIN document_versions target
ON target.document_id = dv.document_id
AND target.major = dv.major
WHERE target.id = @target_version_id
)
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"target_version_id": targetVersionID,
"state": DocumentVersionSignatureStateRequested,
"now": time.Now(),
}
maps.Copy(args, scope.SQLArguments())
if _, err := conn.Exec(ctx, q, args); err != nil {
return fmt.Errorf("cannot move requested document version signatures to the newly published version: %w", err)
}
return nil
}
func (pvss *DocumentVersionSignatures) DeleteRequestedByDocumentIDBelowMajor(
ctx context.Context,
conn pg.Tx,