-- ============================================================================
-- MARS-1409 Step 08: Install A_WORKFLOW_HISTORY trigger
-- ============================================================================
-- Purpose: Update trigger to mark A_SOURCE_FILE_RECEIVED as INGESTED
--          when WORKFLOW_SUCCESSFUL is set to 'Y'
-- ============================================================================

PROMPT Installing A_WORKFLOW_HISTORY (new_version)...
@@new_version/A_WORKFLOW_HISTORY.sql

PROMPT
DECLARE
    v_status VARCHAR2(20);
BEGIN
    SELECT status INTO v_status
    FROM all_objects
    WHERE owner = 'CT_MRDS'
      AND object_name = 'A_WORKFLOW_HISTORY'
      AND object_type = 'TRIGGER';
    DBMS_OUTPUT.PUT_LINE('A_WORKFLOW_HISTORY status: ' || v_status);
    IF v_status != 'VALID' THEN
        RAISE_APPLICATION_ERROR(-20002, 'ERROR: A_WORKFLOW_HISTORY compiled with errors (status=' || v_status || '). Installation aborted.');
    END IF;
EXCEPTION
    WHEN NO_DATA_FOUND THEN
        RAISE_APPLICATION_ERROR(-20001, 'ERROR: A_WORKFLOW_HISTORY not found after installation');
END;
/
