-- Migration: Add document_id support to protection_actions_log
-- 036_protection_actions_documents.sql
-- Adds document_id column to protection_actions_log for documents table support

-- Add document_id column for documents table (UUID)
ALTER TABLE protection_actions_log ADD COLUMN IF NOT EXISTS document_id UUID REFERENCES documents(id) ON DELETE CASCADE;

-- Create index for document_id
CREATE INDEX IF NOT EXISTS idx_protection_actions_log_document_id ON protection_actions_log(document_id) WHERE document_id IS NOT NULL;

-- Update comments
COMMENT ON COLUMN protection_actions_log.document_id IS 'Reference to documents table (UUID) for discovery documents';
COMMENT ON COLUMN protection_actions_log.file_id IS 'Reference to scan_files table (INTEGER) for legacy scans';

