Files
khb_microservices/packages/khb_common/migrations/029_contractor_email.sql
Yuri Yaryshev 2987e8f139
Some checks failed
ci / test (push) Successful in 35s
ci / deploy (push) Has been cancelled
Письма подрядчикам: отбор адресата, khb-mail, журнал contractor_email, правило в промте (п.82)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 22:57:28 +03:00

39 lines
3.0 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Письма подрядчикам, отправленные агентами-ассистентами от имени менеджера (docs/proposed/modules/khbuild_assistant_prep/contractor-email.md).
-- Журнал исходящих: точное время, отправитель, адресаты и код письма (ref) нужны отдельному сервису разбора входящих,
-- чтобы сопоставлять ответы подрядчиков с исходящим (ref в теме и в конце письма, message_id, thread_id).
create table if not exists contractor_email (
id bigserial primary key,
ref text not null unique, -- KHB-ГГММДД-XXXX: в теме письма и мелким шрифтом в конце
status text not null check (status in ('sent', 'failed', 'dry_run')),
error text,
created_at timestamptz not null default now(), -- когда запись создана
sent_at timestamptz, -- точное время отправки (null, если не ушло)
message_id text, -- RFC Message-ID, который мы задали (Gmail может его переписать)
gmail_id text,
thread_id text,
manager_person_id text not null,
project_job_id text,
project_name text,
task_ids jsonb not null default '[]'::jsonb, -- работы, по которым выбран подрядчик
vendor_account_id text,
vendor_name text,
to_name text,
to_email text,
to_source text, -- откуда адрес: assigned_person / vendor_email / vendor_user
cc_emails jsonb not null default '[]'::jsonb,
from_name text,
from_email text,
subject text,
body_text text,
template_version text,
work_date date, -- на какую дату вызван подрядчик
work_note text,
source_channel text, -- чат Slack, из которого пришла просьба
jt_comment_id text, -- комментарий в JobTread (история проекта)
reply_to_ref text -- зарезервировано: входящее письмо, сопоставленное с этим (сервис разбора входящих)
);
create index if not exists contractor_email_manager_idx on contractor_email (manager_person_id, created_at desc);
create index if not exists contractor_email_dup_idx on contractor_email (to_email, project_job_id, work_date);
create index if not exists contractor_email_msg_idx on contractor_email (message_id);
alter table contractor_email enable row level security;