-- ====================================================================
-- A_TASK_HISTORY Table
-- ====================================================================
-- Purpose: Log of subprocesses being part of the DWH flows
-- ====================================================================

CREATE TABLE CT_MRDS.A_TASK_HISTORY (
    A_TASK_HISTORY_KEY NUMBER(38,0) NOT NULL ENABLE,
    A_WORKFLOW_HISTORY_KEY NUMBER(38,0),
    TASK_RUN_ID VARCHAR2(255 BYTE) COLLATE "USING_NLS_COMP",
    TASK_NAME VARCHAR2(255 BYTE) COLLATE "USING_NLS_COMP",
    TASK_START TIMESTAMP(6),
    TASK_END TIMESTAMP(6),
    TASK_STATUS VARCHAR2(200) COLLATE "USING_NLS_COMP"
) TABLESPACE "DATA";

-- Comments
COMMENT ON TABLE CT_MRDS.A_TASK_HISTORY IS 'Log of subprocesses being part of the DWH flows';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.A_TASK_HISTORY_KEY IS 'Surrogate key for logged subprocesses';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.A_WORKFLOW_HISTORY_KEY IS 'Technical key to identify a load operation. Generated with Oracle sequence "CT_MRDS.SA_TASK_HISTORY_KEY_SEQ"';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.TASK_NAME IS 'Mapping name of the logged subprocess';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.TASK_START IS 'Start time of the subprocess';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.TASK_END IS 'End time of the subprocess';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.TASK_STATUS IS 'Indicates that the subprocess completed successfully. Allowed values are ''RUNNING'',''FAILED'' and ''SUCCESS''.';

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

-- Bitmap index for task history queries  
CREATE BITMAP INDEX CT_MRDS.A_TASK_HISTORY_IDX1 
ON CT_MRDS.A_TASK_HISTORY (A_WORKFLOW_HISTORY_KEY)
TABLESPACE "DATA";