-- 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,
    IS_ARCHIVE_ENABLED       CHAR(1)      DEFAULT 'N' NOT NULL,
    IS_KEEP_IN_TRASH         CHAR(1)      DEFAULT 'Y' NOT NULL
);

-- Add check constraints
ALTER TABLE CT_MRDS.A_SOURCE_FILE_CONFIG ADD CONSTRAINT 
    CHK_ARCHIVAL_STRATEGY CHECK (
        ARCHIVAL_STRATEGY IN ('THRESHOLD_BASED', 'MINIMUM_AGE_MONTHS', 'HYBRID')
    );

ALTER TABLE CT_MRDS.A_SOURCE_FILE_CONFIG ADD CONSTRAINT 
    CHK_IS_ARCHIVE_ENABLED CHECK (IS_ARCHIVE_ENABLED IN ('Y', 'N'));

ALTER TABLE CT_MRDS.A_SOURCE_FILE_CONFIG ADD CONSTRAINT 
    CHK_IS_KEEP_IN_TRASH CHECK (IS_KEEP_IN_TRASH IN ('Y', 'N'));

-- Add comments
COMMENT ON COLUMN CT_MRDS.A_SOURCE_FILE_CONFIG.ARCHIVAL_STRATEGY IS 
    'Archival strategy: THRESHOLD_BASED (days), MINIMUM_AGE_MONTHS (0=current month, N=retain N months), 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)';

COMMENT ON COLUMN CT_MRDS.A_SOURCE_FILE_CONFIG.IS_ARCHIVE_ENABLED IS 
    'Y=Enable archiving, N=Skip archiving. Controls if table participates in archival process. Added in MARS-828 v3.3.0';

COMMENT ON COLUMN CT_MRDS.A_SOURCE_FILE_CONFIG.IS_KEEP_IN_TRASH IS 
    'Y=Keep files in TRASH after archiving, N=Delete immediately. Controls TRASH retention policy. Added in MARS-828 v3.3.0';

-- 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', 'IS_ARCHIVE_ENABLED', 'IS_KEEP_IN_TRASH')
ORDER BY column_id;

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