Re-sequence taxonomy sort orders on apply; report them in validate#213
Merged
Conversation
Competition/category/round sort_order in the DB is defined as the entity's 1-based index in metadata.shared.json, enforced by unique indexes. apply get-or-created only the draft's own taxonomy and never re-sequenced the rest, so inserting or reordering a competition mid-array left the later rows at their old orders — and the next apply that created an entity at a now-occupied index died with an opaque Postgres 23505 on ux_competition_sort_order. apply now reconciles the families a draft can shift (competitions, categories, and the target competition's rounds) to their registry positions before creating anything, via a two-phase park-past-the-end/number-1..N update that never transiently violates the unique index. validate previews and reports the pending renumbering (informational, never blocking), and a stored taxonomy row whose slug the registry can't place is surfaced as a blocking orphan rather than crashing apply. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Competition / category / round
sort_orderin the DB is defined as the entity's 1-based index inmetadata.shared.json, enforced by unique indexes (ux_competition_sort_order,ux_category_sort_order, and two partial composite round indexes).applyget-or-created only the draft's own taxonomy and never re-sequenced the rest, so inserting or reordering a competition mid-array left the later rows at their old orders — and the nextapplythat created an entity at a now-occupied index died with an opaque Postgres 23505.validatedidn't catch it: its preview only probed create-vs-reuse, never sort order.What
applyis now the authoritative re-sequencer. Before creating anything, it reconciles the families a draft can shift — competitions and categories (global spaces) and the target competition's rounds — to their registry positions, freeing the slot a new entity will claim.TaxonomyResequencer): park every mover just past the live range, flush, then number1..N(all targets below the parked range), wrapped in one transaction so a mid-run failure can't leave parked values committed. PostgreSQL checks a non-deferrable unique index per-row, so this vacate-then-fill is required — it mirrors the existingReplaceJoinRowsAsyncidiom and handles arbitrary reorderings, not just monotone shifts.validatereports the pending renumbering as informationalre-sequence …lines (never blocking), so the operator sees exactly whatapplywill do.taxonomy-orphanerror, instead of silently passingvalidateand then crashingapply.TaxonomyKindenum.Covered by new Postgres integration tests (mid-array insertion, a non-monotone swap, per-round and per-category re-sequencing, the no-op case, and competition/round orphan detection).
🤖 Generated with Claude Code