-- ====================================================================
-- A_TABLE_STAT Table
-- ====================================================================
-- Purpose: Store current table statistics and archival thresholds
-- ====================================================================

CREATE TABLE CT_MRDS.A_TABLE_STAT (
    A_TABLE_STAT_KEY                  NUMBER(38,0) PRIMARY KEY, 
    A_SOURCE_FILE_CONFIG_KEY          NUMBER(38,0) NOT NULL,
    TABLE_NAME                        VARCHAR2(200) NOT NULL,
    FILE_COUNT                        NUMBER(38,0),
    OVER_ARCH_THRESOLD_FILE_COUNT     NUMBER(38,0),
    ROW_COUNT                         NUMBER(38,0), 
    OVER_ARCH_THRESOLD_ROW_COUNT      NUMBER(38,0), 
    SIZE                              NUMBER(38,0),
    OVER_ARCH_THRESOLD_SIZE           NUMBER(38,0),
    ARCH_THRESHOLD_DAYS               NUMBER(4,0),
    CREATED                           TIMESTAMP(6) DEFAULT SYSTIMESTAMP,
    ARCHIVAL_STRATEGY                 VARCHAR2(30),
    ARCH_MINIMUM_AGE_MONTHS           NUMBER(4,0),
    IS_WORKFLOW_SUCCESS_REQUIRED       CHAR(1),
    CONSTRAINT A_TABLE_STAT_UK1 UNIQUE(A_SOURCE_FILE_CONFIG_KEY)
) TABLESPACE "DATA";

COMMENT ON COLUMN CT_MRDS.A_TABLE_STAT.ARCHIVAL_STRATEGY IS 'Archival strategy used when statistics were gathered (THRESHOLD_BASED, MINIMUM_AGE_MONTHS, HYBRID). Populated by FILE_ARCHIVER.GATHER_TABLE_STAT (MARS-1409)';
COMMENT ON COLUMN CT_MRDS.A_TABLE_STAT.ARCH_MINIMUM_AGE_MONTHS IS 'Minimum age threshold in months used when statistics were gathered. Populated for MINIMUM_AGE_MONTHS and HYBRID strategies; NULL for THRESHOLD_BASED. Complements ARCH_THRESHOLD_DAYS. Populated by FILE_ARCHIVER.GATHER_TABLE_STAT (MARS-1409)';
COMMENT ON COLUMN CT_MRDS.A_TABLE_STAT.IS_WORKFLOW_SUCCESS_REQUIRED IS 'Reflects IS_WORKFLOW_SUCCESS_REQUIRED value from A_SOURCE_FILE_CONFIG at time statistics were gathered. Y=counts include only WORKFLOW_SUCCESSFUL=Y rows, N=all rows counted regardless of workflow status. Added MARS-1409';

-- Unique constraint index (from production export)
CREATE UNIQUE INDEX "CT_MRDS"."A_TABLE_STAT_UK1" 
ON "CT_MRDS"."A_TABLE_STAT" ("A_SOURCE_FILE_CONFIG_KEY") 
TABLESPACE "DATA";