Add task priority field

Introduce a rank-style priority on tasks, scoped by
(organization_id, state). New tasks auto-assign the next
priority. Reordering uses the same CTE-based algorithm as
trust center references and compliance external URLs.
Exposed through GraphQL, MCP, and the PRIORITY order field.

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2026-03-26 19:05:13 +01:00
parent 72a48ff6b1
commit 257cbcf826
10 changed files with 234 additions and 51 deletions

View File

@@ -0,0 +1,19 @@
ALTER TABLE tasks ADD COLUMN priority INTEGER;
WITH ranked_tasks AS (
SELECT
id,
ROW_NUMBER() OVER (PARTITION BY organization_id, state ORDER BY created_at DESC, id DESC) AS rn
FROM tasks
)
UPDATE tasks t
SET priority = rt.rn
FROM ranked_tasks rt
WHERE t.id = rt.id;
ALTER TABLE tasks ALTER COLUMN priority SET NOT NULL;
ALTER TABLE tasks
ADD CONSTRAINT tasks_organization_id_state_priority_key
UNIQUE (organization_id, state, priority)
DEFERRABLE INITIALLY DEFERRED;