reorder

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package reorder implements a single, collision-safe algorithm for moving a row to a new 1-based position among its ord-ordered siblings. It is shared by planengine (tickets within a plan, phases within a ticket) and tasklist (tasks within a list) so the three levels of the plan hierarchy reorder identically.

The wrinkle every caller faces is the same: sibling rows carry a UNIQUE(parent, ord) constraint, so naively shifting ords to make room for the moved row risks a collision mid-transaction (e.g. moving row ord=3 to ord=1 requires bumping ord=1→2 and ord=2→3, but if the driver applies those in the wrong order it collides with the row already sitting at the target ord). Reposition sidesteps this with a two-pass negative-ord transaction: every sibling is first moved to a distinct negative ord (guaranteed to never collide with any positive ord), then moved to its final positive ord in the new sequence.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reposition

func Reposition(tx *sql.Tx, table, idCol, ordCol, parentCol string, parentID, movingID int64, targetPos int) (int, error)

Reposition moves the row identified by movingID to targetPos (1-based) among its siblings — the rows sharing the same parentID in parentCol, ordered by ordCol — within tx. targetPos is clamped to [1, len(siblings)] so an out-of-range request lands at the nearest valid end rather than erroring. Returns the new ord assigned to movingID.

table, idCol, ordCol, and parentCol are the schema names to operate on (e.g. "tickets", "id", "ord", "plan_id"); callers pass their own since each level of the plan hierarchy has its own table. movingID must be one of the siblings under parentID or an error is returned.

Types

This section is empty.

Source Files

  • reorder.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL