-- Migration: Add document_id support to field_masking_log
-- 037_field_masking_documents.sql
-- Adds document_id column to field_masking_log for documents table support

-- Add document_id column for documents table (UUID)
ALTER TABLE field_masking_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_field_masking_log_document_id ON field_masking_log(document_id) WHERE document_id IS NOT NULL;

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

