Skip to content

Prevent duplicate active document versions#1046

Merged
SachaProbo merged 1 commit intomainfrom
SachaProbo/dup-pending-versions
Apr 15, 2026
Merged

Prevent duplicate active document versions#1046
SachaProbo merged 1 commit intomainfrom
SachaProbo/dup-pending-versions

Conversation

@SachaProbo
Copy link
Copy Markdown
Contributor

@SachaProbo SachaProbo commented Apr 14, 2026

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.


Summary by cubic

Prevents multiple active versions (DRAFT or PENDING_APPROVAL) per document by enforcing the unique partial index document_one_active_version_idx. Violations now return ErrResourceAlreadyExists.

  • Migration
    • Deletes duplicate active versions, keeping the oldest and preferring PENDING_APPROVAL over DRAFT.
    • Drops document_one_draft_version_idx and creates document_one_active_version_idx on document_versions (document_id) for DRAFT/PENDING_APPROVAL.

Written for commit 0b9686f. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="pkg/coredata/migrations/20260414T120000Z.sql">

<violation number="1" location="pkg/coredata/migrations/20260414T120000Z.sql:17">
P1: This unique index can fail migration on existing data because it adds a new cross-status uniqueness rule without first deduplicating active versions.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread pkg/coredata/migrations/20260414T120000Z.sql
@SachaProbo SachaProbo force-pushed the SachaProbo/dup-pending-versions branch 5 times, most recently from efe9938 to b40c0aa Compare April 14, 2026 20:10
Copy link
Copy Markdown
Contributor

@gearnode gearnode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SachaProbo SachaProbo force-pushed the SachaProbo/dup-pending-versions branch 2 times, most recently from f70d635 to 9e57b44 Compare April 15, 2026 12:29
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>
@SachaProbo SachaProbo force-pushed the SachaProbo/dup-pending-versions branch from 9e57b44 to 0b9686f Compare April 15, 2026 12:39
@SachaProbo SachaProbo merged commit 0b9686f into main Apr 15, 2026
17 checks passed
@SachaProbo SachaProbo deleted the SachaProbo/dup-pending-versions branch April 15, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants