-- MARS-828: Add archival strategy columns to A_SOURCE_FILE_CONFIG
-- Author: Grzegorz Michalski
-- Date: 2026-01-27
-- Description: Adds ARCHIVAL_STRATEGY and MINIMUM_AGE_MONTHS columns to support flexible archival strategies

PROMPT ========================================
PROMPT MARS-828: Adding archival strategy columns
PROMPT ========================================

-- Add new columns
ALTER TABLE CT_MRDS.A_SOURCE_FILE_CONFIG ADD (
    ARCHIVAL_STRATEGY        VARCHAR2(30) DEFAULT 'THRESHOLD_BASED' NOT NULL,
    MINIMUM_AGE_MONTHS       NUMBER(3)    DEFAULT NULL
);

-- Add check constraint for valid strategies
ALTER TABLE CT_MRDS.A_SOURCE_FILE_CONFIG ADD CONSTRAINT 
    CHK_ARCHIVAL_STRATEGY CHECK (
        ARCHIVAL_STRATEGY IN ('THRESHOLD_BASED', 'CURRENT_MONTH_ONLY', 'MINIMUM_AGE_MONTHS', 'HYBRID')
    );

-- Add comments
COMMENT ON COLUMN CT_MRDS.A_SOURCE_FILE_CONFIG.ARCHIVAL_STRATEGY IS 
    'Archival strategy: THRESHOLD_BASED (days), CURRENT_MONTH_ONLY (exclude current month), MINIMUM_AGE_MONTHS (minimum age), HYBRID (combination)';

COMMENT ON COLUMN CT_MRDS.A_SOURCE_FILE_CONFIG.MINIMUM_AGE_MONTHS IS 
    'Minimum age in months for archival (used with MINIMUM_AGE_MONTHS or HYBRID strategies)';

-- Verify columns added
SELECT 
    column_name, 
    data_type, 
    data_length,
    nullable,
    data_default
FROM all_tab_columns 
WHERE owner = 'CT_MRDS' 
  AND table_name = 'A_SOURCE_FILE_CONFIG'
  AND column_name IN ('ARCHIVAL_STRATEGY', 'MINIMUM_AGE_MONTHS')
ORDER BY column_id;

PROMPT ========================================
PROMPT Archival strategy columns added successfully
PROMPT ========================================
