Files
multica/server/migrations/093_issue_position_backfill.down.sql
Naiyuan Qing 0127d6a258 fix(issues): address MUL-2314 reviewer notes 1-4
#1 sort default: missing sort_by, unknown sort_by, and illegal
sort_direction all collapse to created_at DESC, id DESC (was ASC).
Order-asserting test cases added for every degenerate input.

#2 onboarding position: extract nextIssuePosition helper. Welcome
issue + sub-issues + the existing CreateIssue path all route through
it instead of inheriting Go's Position=0 default. This consolidates
the three create call-sites so a fourth path cannot regress.

#3 rebalance hot path: replace full-bucket scan with a neighbor-only
SQL query (GetIssueNeighborGap) used by MaybeEnqueueRebalance. Hot
path stays O(1); worker still does the full bucket scan when actually
rebalancing. Bucket-edge issues use COALESCE sentinels so missing
neighbours never trigger spurious rebalances.

#4 migration: up is now order-preserving (position ASC, created_at
DESC, id DESC) and idempotent (skips buckets that are already sparse).
down drops only the index; data restore is per runbook snapshot so a
destructive UPDATE issue SET position = 0 cannot wipe drag edits.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
2026-05-18 13:58:45 +08:00

15 lines
885 B
SQL

-- Drop only the supporting index. The `position` column itself is NOT
-- reset, because doing so would destroy any drag-drop edits and freshly
-- created issues whose `position` values were assigned AFTER the up
-- migration ran — i.e. real user data, not just backfilled values.
--
-- Per MUL-2314 reviewer note #4: rolling back the data side of this
-- migration is out-of-band. The deploy runbook for MUL-2314 takes a
-- `position` snapshot (`pg_dump --table=issue --data-only` filtered to
-- `id, position`) immediately before applying 093.up. If a rollback is
-- needed, restore from that snapshot. Doing a destructive `UPDATE issue
-- SET position = 0` here would silently lose every drag and every newly
-- created issue's sparse position, which is exactly the regression the
-- whole change set is meant to prevent.
DROP INDEX IF EXISTS idx_issue_workspace_status_position;