-- "Control:" todo: задачу поставили исполнителю, а контролёр (например CEO) получил парное todo "Control: ...". -- Слежение за парами: исполнитель закрыл todo -> контролёру "(выполнено)" и сообщение; 2 дня без действий после срока -> "(просрочено)". create table control_todo ( id uuid primary key default gen_random_uuid(), controller_person_id uuid not null references person(id), -- чей агент пишет контролёру (чат контролёра) executor_task_id text not null, -- todo исполнителя в JobTread control_task_id text not null unique, -- парное "Control:" todo контролёра executor_name text, -- название todo исполнителя (для сообщения, пока нет в зеркале) control_due date, -- срок Control todo (срок исполнителя + 2 дня) status text not null default 'active' check (status in ('active', 'overdue', 'done', 'closed')), created_at timestamptz not null default now(), notified_at timestamptz, -- когда агент последний раз сообщал контролёру о смене статуса updated_at timestamptz not null default now() ); create index control_todo_open_idx on control_todo (status) where status in ('active', 'overdue'); alter table control_todo enable row level security;