Prevent duplicate active document versions
Replace the draft-only unique index with one covering both DRAFT and PENDING_APPROVAL statuses, ensuring a document can have at most one active version at a time. Deduplicate any existing data before creating the index, prioritizing PENDING_APPROVAL over DRAFT. Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -253,7 +253,7 @@ VALUES (
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr.Code == "23505" {
|
||||
if pgErr.ConstraintName == "document_versions_document_id_major_minor_key" || pgErr.ConstraintName == "document_one_draft_version_idx" {
|
||||
if pgErr.ConstraintName == "document_versions_document_id_major_minor_key" || pgErr.ConstraintName == "document_one_active_version_idx" {
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user