-- ====================================================================
-- A_WORKFLOW_HISTORY Table
-- ====================================================================
-- Purpose: Load history table for the Data Warehouse (DWH)
-- ====================================================================

CREATE TABLE CT_MRDS.A_WORKFLOW_HISTORY (
    A_WORKFLOW_HISTORY_KEY NUMBER(38,0) NOT NULL ENABLE, 
    ORCHESTRATION_RUN_ID VARCHAR2(300),
    WORKFLOW_NAME VARCHAR2(255 BYTE) COLLATE "USING_NLS_COMP", 
    WORKFLOW_START TIMESTAMP(6), 
    WORKFLOW_END TIMESTAMP(6), 
    WORKFLOW_STATUS VARCHAR2(200),
    DBT_INVOCATION_ID VARCHAR2(200)
) TABLESPACE "DATA";

-- Comments
COMMENT ON TABLE CT_MRDS.A_WORKFLOW_HISTORY IS 'Load history table for the Data Warehouse (DWH)';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.A_WORKFLOW_HISTORY_KEY IS 'Technical key to identify a load operation. Generated with Oracle sequence "CT_MRDS.SEQ_WORKFLOW_HISTORY"';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.ORCHESTRATION_RUN_ID IS 'Run_id of the workflow';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.WORKFLOW_NAME IS 'The name of the workflow, this is always w_DWH_RAR_LOAD';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.WORKFLOW_START IS 'Start time of the Informatica workflow';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.WORKFLOW_END IS 'End time of the Informatica workflow';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.WORKFLOW_STATUS IS 'Overall status of the workflow, either RUNNING|SUCCESS|ERROR';

-- Grants
GRANT SELECT, INSERT, UPDATE, DELETE ON CT_MRDS.A_WORKFLOW_HISTORY TO MRDS_LOADER;

-- Bitmap index for workflow history queries
CREATE BITMAP INDEX CT_MRDS.A_WORKFLOW_HISTORY_IDX1 
ON CT_MRDS.A_WORKFLOW_HISTORY (A_WORKFLOW_HISTORY_KEY, WORKFLOW_NAME, WORKFLOW_START) 
TABLESPACE "DATA";