-- Миграция: consent_revoked_date + bot_processing_logs
-- Дата: 02.06.2026
-- Описание: Добавление поля consent_revoked_date в bot_users и создание таблицы bot_processing_logs

-- 1. Consent revoked date
ALTER TABLE bot_users ADD COLUMN IF NOT EXISTS consent_revoked_date TIMESTAMP NULL;

-- 2. BotProcessingLog table
CREATE TABLE IF NOT EXISTS bot_processing_logs (
    id BIGSERIAL PRIMARY KEY,
    user_id BIGINT NOT NULL REFERENCES bot_users(id) ON DELETE CASCADE,
    conversation_id BIGINT REFERENCES bot_conversations(id) ON DELETE SET NULL,
    step VARCHAR(50) NOT NULL,
    status VARCHAR(20) DEFAULT 'ok',
    message TEXT,
    detail TEXT,
    created_at TIMESTAMP DEFAULT now()
);

-- Индексы для производительности
CREATE INDEX IF NOT EXISTS idx_bot_processing_logs_user_id ON bot_processing_logs(user_id);
CREATE INDEX IF NOT EXISTS idx_bot_processing_logs_conversation_id ON bot_processing_logs(conversation_id);
