-- Verify all required tables exist
-- Migration: 025_verify_all_tables.sql

-- Legal & eDiscovery Tables
DO $$
BEGIN
    -- Cases
    IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'cases') THEN
        RAISE EXCEPTION 'Table cases does not exist';
    END IF;
    
    -- Legal Requests
    IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'legal_requests') THEN
        RAISE EXCEPTION 'Table legal_requests does not exist';
    END IF;
    
    -- Holds
    IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'holds') THEN
        RAISE EXCEPTION 'Table holds does not exist';
    END IF;
    
    -- Review Sets
    IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'review_sets') THEN
        RAISE EXCEPTION 'Table review_sets does not exist';
    END IF;
    
    -- Collections
    IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'collections') THEN
        RAISE EXCEPTION 'Table collections does not exist';
    END IF;
    
    -- Case Custodians
    IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'case_custodians') THEN
        RAISE EXCEPTION 'Table case_custodians does not exist';
    END IF;
    
    -- Classification Tables
    IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'structured_fields') THEN
        RAISE EXCEPTION 'Table structured_fields does not exist';
    END IF;
    
    IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'classification_rules') THEN
        RAISE EXCEPTION 'Table classification_rules does not exist';
    END IF;
    
    IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'ml_models') THEN
        RAISE EXCEPTION 'Table ml_models does not exist';
    END IF;
    
    RAISE NOTICE 'All required tables exist';
END $$;

