ready to merge and ready to discard as states

This commit is contained in:
Ian Gulliver
2026-10-19 17:53:54 -07:00
parent fb79919ebb
commit 2bb527aca0
11 changed files with 394 additions and 293 deletions
@@ -0,0 +1,10 @@
ALTER TABLE tasks ADD COLUMN ready TEXT NOT NULL DEFAULT '';
UPDATE tasks SET ready = coalesce((
SELECT CASE e.kind WHEN 'task.ready' THEN 'merge' ELSE 'discard' END FROM events e
WHERE e.task_id = tasks.id AND e.kind IN ('task.ready', 'task.discard_suggested')
AND NOT EXISTS (
SELECT 1 FROM events l WHERE l.task_id = tasks.id AND l.seq > e.seq
AND (l.kind = 'inbox.created' OR (l.kind = 'snapshot.created' AND json_extract(l.payload, '$.trigger') != 'answer'))
)
ORDER BY e.seq DESC LIMIT 1
), '') WHERE status = 'active';