Files
mkd/backend/migrate_candidate_events.sql
2026-02-04 00:17:04 +05:00

52 lines
2.7 KiB
SQL
Executable File
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.
-- Миграция для создания таблицы событий кандидатов
-- Выполните этот скрипт для обновления существующей базы данных
-- Создание типа candidate_event_type
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'candidate_event_type') THEN
CREATE TYPE candidate_event_type AS ENUM (
'call', -- Созвон
'interview_1', -- Первое собеседование
'interview_2', -- Второе собеседование
'interview_3', -- Третье собеседование
'test_task', -- Тестовое задание
'offer', -- Оффер
'offer_accepted', -- Оффер принят
'offer_rejected', -- Оффер отклонен
'probation_start', -- Начало испытательного срока
'hired', -- Трудоустроен
'rejected', -- Отклонен
'other' -- Другое
);
END IF;
END$$;
-- Создание типа candidate_event_result
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'candidate_event_result') THEN
CREATE TYPE candidate_event_result AS ENUM ('success', 'failed', 'pending', 'cancelled');
END IF;
END$$;
-- Создание таблицы событий кандидата
CREATE TABLE IF NOT EXISTS candidate_events (
id VARCHAR(50) PRIMARY KEY,
candidate_id VARCHAR(50) NOT NULL REFERENCES candidates(id) ON DELETE CASCADE,
event_type candidate_event_type NOT NULL,
event_date TIMESTAMPTZ NOT NULL,
notes TEXT, -- Заметки о событии
result candidate_event_result DEFAULT 'pending', -- Результат события
interviewer TEXT, -- Кто проводил (для собеседований)
location TEXT, -- Место проведения (офис, онлайн и т.д.)
duration_minutes INTEGER, -- Длительность в минутах
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Создание индексов
CREATE INDEX IF NOT EXISTS idx_candidate_events_candidate ON candidate_events(candidate_id);
CREATE INDEX IF NOT EXISTS idx_candidate_events_type ON candidate_events(event_type);
CREATE INDEX IF NOT EXISTS idx_candidate_events_date ON candidate_events(event_date DESC);