Add task priority enum and rename priority to rank
The existing integer priority field represents positional ordering within a state, not semantic importance. Rename it to rank and introduce a new priority field with enum values URGENT, HIGH, MEDIUM and LOW across the entire stack. Rank is now scoped to (state, priority) so tasks are ordered within each priority group. A generated priority_rank column combines both fields into a single sortable integer for cursor pagination. Dragging a task across priority groups updates its priority automatically based on the drop position neighbors. The backend first moves the task to the new group then repositions it at the target rank. The migration defaults existing rows to MEDIUM priority and backfills ranks per (state, priority) group. Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
36
pkg/coredata/migrations/20260330T120000Z.sql
Normal file
36
pkg/coredata/migrations/20260330T120000Z.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
-- Rename priority to rank
|
||||
ALTER TABLE tasks RENAME COLUMN priority TO rank;
|
||||
|
||||
ALTER TABLE tasks DROP CONSTRAINT tasks_organization_id_state_priority_key;
|
||||
|
||||
-- Add task priority enum
|
||||
CREATE TYPE task_priority AS ENUM ('URGENT', 'HIGH', 'MEDIUM', 'LOW');
|
||||
|
||||
ALTER TABLE tasks ADD COLUMN priority task_priority NOT NULL DEFAULT 'MEDIUM'::task_priority;
|
||||
|
||||
ALTER TABLE tasks ALTER COLUMN priority DROP DEFAULT;
|
||||
|
||||
-- Rank is now scoped to (state, priority) — backfill ranks per group
|
||||
WITH ranked AS (
|
||||
SELECT id, ROW_NUMBER() OVER (
|
||||
PARTITION BY organization_id, state, priority
|
||||
ORDER BY rank
|
||||
) AS new_rank
|
||||
FROM tasks
|
||||
)
|
||||
UPDATE tasks SET rank = ranked.new_rank FROM ranked WHERE tasks.id = ranked.id;
|
||||
|
||||
ALTER TABLE tasks
|
||||
ADD CONSTRAINT tasks_organization_id_state_priority_rank_key
|
||||
UNIQUE (organization_id, state, priority, rank)
|
||||
DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
-- Computed column for composite ordering (priority level then rank)
|
||||
ALTER TABLE tasks ADD COLUMN priority_rank int GENERATED ALWAYS AS (
|
||||
(CASE priority
|
||||
WHEN 'URGENT' THEN 1
|
||||
WHEN 'HIGH' THEN 2
|
||||
WHEN 'MEDIUM' THEN 3
|
||||
WHEN 'LOW' THEN 4
|
||||
END) * 1000000 + rank
|
||||
) STORED;
|
||||
Reference in New Issue
Block a user