feat(db): trigger sync_task_status_from_claude_job promote task naar DONE
Postgres AFTER-trigger op claude_jobs.status zet de bijbehorende task automatisch op DONE zodra de job DONE wordt — werkt ongeacht welke client de update doet (MCP-server, Server Action, raw SQL). Idempotent: WHERE status <> 'DONE' voorkomt no-op updates die de bestaande notify_task_change-trigger zouden doen vuren. Die laatste verzorgt de pg_notify naar /api/realtime/solo zodat de UI synct. - migration: prisma/migrations/20260501110000_sync_task_status_from_claude_job - doc: nieuwe sectie 'Auto-promote task naar DONE' in architecture.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0605838b99
commit
36874a19dc
2 changed files with 40 additions and 0 deletions
|
|
@ -0,0 +1,36 @@
|
|||
-- Sync task.status to DONE wanneer een ClaudeJob afgerond wordt.
|
||||
--
|
||||
-- Wanneer de agent (via MCP `update_job_status('done')` of een Server
|
||||
-- Action) een ClaudeJob op DONE zet, willen we dat de bijbehorende
|
||||
-- Task automatisch óók op DONE komt. Anders blijft de kaart in de
|
||||
-- "Te doen"-kolom staan terwijl de job-badge "Klaar" toont.
|
||||
--
|
||||
-- We doen dit op DB-niveau zodat het werkt ongeacht welke client de
|
||||
-- update doet (MCP-server, Server Action, raw SQL). De bestaande
|
||||
-- notify_task_change-trigger vuurt automatisch op de task-UPDATE en
|
||||
-- stuurt de pg_notify naar /api/realtime/solo, dus de UI synct
|
||||
-- zonder extra plumbing.
|
||||
--
|
||||
-- Idempotent: WHERE-clause voorkomt no-op updates die de task-trigger
|
||||
-- onnodig doen vuren.
|
||||
|
||||
CREATE OR REPLACE FUNCTION sync_task_status_from_claude_job() RETURNS trigger AS $$
|
||||
BEGIN
|
||||
IF NEW.status = 'DONE' THEN
|
||||
IF (TG_OP = 'INSERT')
|
||||
OR (TG_OP = 'UPDATE' AND OLD.status IS DISTINCT FROM 'DONE')
|
||||
THEN
|
||||
UPDATE tasks
|
||||
SET status = 'DONE', updated_at = now()
|
||||
WHERE id = NEW.task_id AND status <> 'DONE';
|
||||
END IF;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DROP TRIGGER IF EXISTS claude_job_status_to_task ON claude_jobs;
|
||||
CREATE TRIGGER claude_job_status_to_task
|
||||
AFTER INSERT OR UPDATE OF status ON claude_jobs
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION sync_task_status_from_claude_job();
|
||||
Loading…
Add table
Add a link
Reference in a new issue