--=============================================================================================================================
-- MARS-1049-ADHOC: Master Installation Script
--=============================================================================================================================
-- Purpose: Execute all MARS-1049-ADHOC scripts to recreate CSDB external tables with encoding support
-- Author: Grzegorz Michalski
-- Date: 2025-11-26
-- Related: MARS-1049 (CSV Encoding Support), MARS-821 (Original CSDB Setup)
--
-- Prerequisites:
--   - FILE_MANAGER v3.2.1+ with pEncoding parameter support
--   - FILE_MANAGER_ODS v2.1.0+ with pEncoding parameter support
--   - Template tables exist in CT_ET_TEMPLATES schema
--   - Proper bucket URIs configured in ENV_MANAGER
--   - Execute as ODS user or with sufficient privileges
--
-- Deployment Sequence:
--   Step 1: Drop existing CSDB external tables
--   Step 2: Recreate all 18 CSDB external tables with WE8MSWIN1252 encoding
--   Step 3: Verify all tables created successfully
--
-- Rollback:
--   No rollback script provided - tables can be recreated using MARS-821 scripts if needed
--=============================================================================================================================

SET SERVEROUTPUT ON
SET ECHO ON
SET VERIFY OFF

-- ===================================================================
-- MARS-1049-ADHOC INSTALL SCRIPT: CSDB External Tables Encoding Update
-- ===================================================================
-- Purpose: Recreate CSDB external tables with WE8MSWIN1252 encoding
-- Author: Grzegorz Michalski
-- Date: 2025-11-26
-- Version: 1.0.0

-- Dynamic spool file generation (using SYS_CONTEXT - no DBA privileges required)
var filename VARCHAR2(100)
BEGIN
    :filename := 'INSTALL_MARS_1049_ADHOC_' || SYS_CONTEXT('USERENV', 'CON_NAME') || '_' || TO_CHAR(SYSDATE,'YYYYMMDD_HH24MISS') || '.log';
END;
/
column filename new_value _filename
select :filename filename from dual;
spool &_filename

PROMPT =========================================================================
PROMPT MARS-1049-ADHOC: CSDB External Tables Encoding Update
PROMPT =========================================================================
PROMPT 
PROMPT This script will:
PROMPT - Update CSDB configurations to WE8MSWIN1252 encoding
PROMPT - Drop existing CSDB external tables (if any)
PROMPT - Recreate 18 CSDB external tables with WE8MSWIN1252 encoding
PROMPT - Verify successful creation
PROMPT 
PROMPT Expected Duration: 2-3 minutes
PROMPT =========================================================================

PROMPT 
PROMPT =========================================================================
PROMPT Step 0: Update CSDB Encoding Configuration
PROMPT =========================================================================
@@00_MARS_1049_ADHOC_update_encoding.sql

PROMPT 
PROMPT =========================================================================
PROMPT Step 1: Drop Existing CSDB External Tables
PROMPT =========================================================================
@@01_MARS_1049_ADHOC_drop_external_tables.sql

PROMPT 
PROMPT =========================================================================
PROMPT Step 2: Recreate CSDB External Tables with Encoding
PROMPT =========================================================================
@@02_MARS_1049_ADHOC_recreate_external_tables.sql

PROMPT 
PROMPT =========================================================================
PROMPT Step 3: Verify External Tables Creation
PROMPT =========================================================================
@@03_MARS_1049_ADHOC_verify_external_tables.sql

PROMPT 
PROMPT =========================================================================
PROMPT MARS-1049-ADHOC Installation - COMPLETED
PROMPT =========================================================================
PROMPT Check the log file for complete installation details.
PROMPT =========================================================================

spool off

PROMPT 
PROMPT =========================================================================
PROMPT MARS-1049-ADHOC Installation Complete
PROMPT =========================================================================
PROMPT 
PROMPT All CSDB external tables have been updated with WE8MSWIN1252 encoding.
PROMPT 
PROMPT =========================================================================

quit;
