dana-medical-site/internal/storage/migrations/0017_reports.sql
2026-10-14 13:33:13 +00:00

25 lines
1.6 KiB
SQL
Raw 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.

-- Отчёты админки: задание, его этапы и готовый файл. Исходный файл не храним —
-- после обработки он не нужен. Результат сопоставления номеров содержит телефоны пациентов
-- (персональные данные), поэтому готовые отчёты хранятся 30 дней и удаляются.
CREATE TABLE reports (
id bigserial PRIMARY KEY,
kind text NOT NULL CHECK (kind IN ('phone_match', 'doctors', 'leads_summary')),
title text NOT NULL,
status text NOT NULL DEFAULT 'running'
CHECK (status IN ('running', 'done', 'failed', 'cancelled')),
stage int NOT NULL DEFAULT 0, -- номер текущего этапа, 0..4
progress int NOT NULL DEFAULT 0, -- 0..100
stages jsonb NOT NULL DEFAULT '[]', -- длительность завершённых этапов, мс
source_name text NOT NULL DEFAULT '',
source_size bigint NOT NULL DEFAULT 0,
summary jsonb NOT NULL DEFAULT '{}', -- итоги: сколько совпало, отличается и т. п.
result bytea,
result_name text NOT NULL DEFAULT '',
error text NOT NULL DEFAULT '',
admin_id bigint REFERENCES admin_users (id) ON DELETE SET NULL,
created_at timestamptz NOT NULL DEFAULT now(),
finished_at timestamptz
);
CREATE INDEX reports_created_idx ON reports (created_at DESC);