-- ===================================================================
-- MARS-1005-PREHOOK ROLLBACK SCRIPT: Restore DATA_EXPORTER v2.14.0
-- ===================================================================
-- Purpose: Rollback for MARS-1005-PREHOOK - Restore DATA_EXPORTER to v2.14.0
-- Author: Grzegorz Michalski
-- Date: 2026-03-10

-- Dynamic spool file generation (using SYS_CONTEXT - no DBA privileges required)
-- IMPORTANT: Ensure log/ directory exists before SPOOL (use host mkdir)
host mkdir log 2>nul

var filename VARCHAR2(100)
BEGIN
    :filename := 'log/ROLLBACK_MARS_1005_PREHOOK_' || SYS_CONTEXT('USERENV', 'CON_NAME') || '_' || TO_CHAR(SYSDATE,'YYYYMMDD_HH24MISS') || '.log';
END;
/
column filename new_value _filename
select :filename filename from dual;
spool &_filename

SET ECHO OFF
SET TIMING ON
SET SERVEROUTPUT ON SIZE UNLIMITED
SET PAUSE OFF

PROMPT =========================================================================
PROMPT MARS-1005-PREHOOK: Rollback - Restore DATA_EXPORTER v2.14.0
PROMPT =========================================================================
PROMPT This will reverse all changes from MARS-1005-PREHOOK installation.
PROMPT
PROMPT Rollback steps:
PROMPT 1. Restore CT_MRDS.DATA_EXPORTER to v2.14.0
PROMPT 2. Verify package versions
PROMPT =========================================================================

-- Confirm rollback with user
ACCEPT continue CHAR PROMPT 'Type YES to continue with rollback, or Ctrl+C to abort: '
WHENEVER SQLERROR EXIT SQL.SQLCODE
BEGIN
    IF '&continue' IS NULL OR TRIM('&continue') IS NULL OR UPPER(TRIM('&continue')) != 'YES' THEN
        RAISE_APPLICATION_ERROR(-20999, 'Rollback aborted by user.');
    END IF;
END;
/
WHENEVER SQLERROR CONTINUE

PROMPT
PROMPT =========================================================================
PROMPT Step 1: Restore DATA_EXPORTER v2.14.0
PROMPT =========================================================================
@@90_MARS_1005_PREHOOK_rollback_DATA_EXPORTER.sql

PROMPT
PROMPT =========================================================================
PROMPT Step 2: Verify Package Versions
PROMPT =========================================================================
@@verify_packages_version.sql

PROMPT
PROMPT =========================================================================
PROMPT MARS-1005-PREHOOK Rollback - COMPLETED
PROMPT =========================================================================

spool off

quit;
