--MARS-770

set verify off
SET serveroutput ON
--SET TIMING ON
whenever sqlerror exit sql.sqlcode rollback;

column owner format a15
column object_name format a30
column spoolname new_value spoolname 

select 'install_package_MarsGeneralRelease_tables_' || name || '_' ||to_char(sysdate,'YYYYMMDD_HH24MISS')||'.log' spoolname from v$pdbs;
spool '&spoolname'


prompt ##### started at time #####
select systimestamp from dual;
prompt ##### database name #####
select name pdb_name from v$pdbs;

--set echo on
--=============================================================================================================================
-- start install --MARS-770 payload
--=============================================================================================================================

CREATE TABLE "CT_MRDS"."A_PROCESS_LOG" (
    a_process_log_key   NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    guid                    VARCHAR2(32),
    Username	            VARCHAR2(128),
    Osuser	                VARCHAR2(128),
    Machine	                VARCHAR2(64),
    Module	                VARCHAR2(64),
    process_name            VARCHAR2(200),
    procedure_name          VARCHAR2(200),
    procedure_parameters    VARCHAR2(20000),
    log_level               VARCHAR2(10),  -- DEBUG, INFO, WARNING, ERROR
    log_message             VARCHAR2(4000),
    log_timestamp           TIMESTAMP DEFAULT SYSTIMESTAMP
);

CREATE TABLE "CT_MRDS"."A_CASPER_FILEVAULT" (
    "A_WORKFLOW_HISTORY_KEY" NUMBER(28,0),
    "WLA_RUN_ID" NUMBER(28,0),
    "WORKFLOW_NAME" CHAR(16 BYTE),
    "FILENAME" VARCHAR2(250 CHAR),
    "STATUS" VARCHAR2(30 CHAR),
    "FILESIZE" NUMBER(28,0),
    "FILE_ID" NUMBER(28,0),
    "IS_TEST" VARCHAR2(5 CHAR),
    "REFERENCE_TIME" TIMESTAMP (6)
    );

CREATE TABLE "CT_MRDS"."A_TASK_HISTORY" (
    "A_TASK_HISTORY_KEY" NUMBER(38,0),
    "A_WORKFLOW_HISTORY_KEY" NUMBER(38,0),
    "TASK_RUN_ID" VARCHAR2(255 BYTE),
    "TASK_NAME" VARCHAR2(255 BYTE),
    "TASK_START" TIMESTAMP (6),
    "TASK_END" TIMESTAMP (6),
    "TASK_SUCCESSFUL" VARCHAR2(200 BYTE),
    "SERVICE_NAME" VARCHAR2(25 BYTE)
    );

COMMENT ON TABLE CT_MRDS.A_TASK_HISTORY IS 'This table logs subprocesses and their execution details.';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.A_TASK_HISTORY_KEY IS 'Surrogate key for logged subprocesses';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.A_WORKFLOW_HISTORY_KEY IS 'Technical key to identify a load operation. Generated with Oracle sequence "CT_MRDS.SA_TASK_HISTORY_KEY_SEQ"';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.TASK_RUN_ID IS 'Unique identifier for the task run';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.TASK_NAME IS 'Mapping name of the logged subprocess';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.TASK_START IS 'Start time of the subprocess';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.TASK_END IS 'End time of the subprocess';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.TASK_SUCCESSFUL IS 'Indicates that the subprocess completed successfully. Allowed values are ''RUNNING'', ''FAILED'', and ''SUCCESS''.';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY.SERVICE_NAME IS 'Database of reference';

CREATE TABLE "CT_MRDS"."A_TASK_HISTORY_SOURCE" (
    "A_TASK_HISTORY_SOURCE_KEY" NUMBER(38,0),
    "A_TASK_HISTORY_KEY" NUMBER(38,0),
    "A_WORKFLOW_HISTORY_SOURCE_KEY" NUMBER(38,0),
    "SOURCE_NAME" VARCHAR2(255 BYTE),
    "ROW_COUNT" NUMBER(38,0),
    "SERVICE_NAME" VARCHAR2(25 BYTE)
    );

COMMENT ON TABLE CT_MRDS.A_TASK_HISTORY_SOURCE IS 'This table logs details of data sources used in load processes.';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_SOURCE.A_TASK_HISTORY_SOURCE_KEY IS 'Technical primary key';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_SOURCE.A_TASK_HISTORY_KEY IS 'Foreign key referencing the subprocess delivering to the target';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_SOURCE.A_WORKFLOW_HISTORY_SOURCE_KEY IS 'Technical key for the workflow history source';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_SOURCE.SOURCE_NAME IS 'Name of the source used in the load process';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_SOURCE.ROW_COUNT IS 'Number of rows read from the source during the load process';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_SOURCE.SERVICE_NAME IS 'Database of reference';

CREATE TABLE "CT_MRDS"."A_TASK_HISTORY_TARGET" (
    "A_TASK_HISTORY_TARGET_KEY" NUMBER(38,0),
    "A_TASK_HISTORY_KEY" NUMBER(38,0),
    "TARGET_NAME" VARCHAR2(255 BYTE),
    "ROW_COUNT_APPLIED" NUMBER(38,0),
    "ROW_COUNT_REJECTED" NUMBER(38,0),
    "LOAD_SUCCESSFUL" CHAR(1 CHAR),
    "SERVICE_NAME" VARCHAR2(25 BYTE)
    );

COMMENT ON TABLE CT_MRDS.A_TASK_HISTORY_TARGET IS 'This table logs details of target data written during load processes.';
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_TARGET.A_TASK_HISTORY_TARGET_KEY IS 'Technical primary key'; 
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_TARGET.A_TASK_HISTORY_KEY IS 'Foreign key referencing the subprocess delivering to the target'; 
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_TARGET.TARGET_NAME IS 'Name of the target where data is written during the load process'; 
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_TARGET.ROW_COUNT_APPLIED IS 'Number of rows successfully applied (written to) the DWH target table during the load process'; 
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_TARGET.ROW_COUNT_REJECTED IS 'Number of rows rejected (NOT written to) the DWH target table during the load process'; 
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_TARGET.LOAD_SUCCESSFUL IS 'Indicates the success of the load process. Allowed values are ''RUNNING'', ''SUCCESS'', and ''FAILED''.'; 
COMMENT ON COLUMN CT_MRDS.A_TASK_HISTORY_TARGET.SERVICE_NAME IS 'Database of reference';

CREATE TABLE "CT_MRDS"."A_WORKFLOW_HISTORY" (
    "A_WORKFLOW_HISTORY_KEY" NUMBER(38,0),
    "ORCHESTRATION_RUN_ID" VARCHAR2(300 BYTE),
    "WORKFLOW_NAME" VARCHAR2(255 BYTE),
    "WORKFLOW_START" TIMESTAMP (6),
    "WORKFLOW_END" TIMESTAMP (6),
    "WORKFLOW_SUCCESSFUL" VARCHAR2(200 BYTE),
    "DBT_INVOCATION_ID" VARCHAR2(200 BYTE),
    "SERVICE_NAME" VARCHAR2(25 BYTE)
    );

COMMENT ON TABLE CT_MRDS.A_WORKFLOW_HISTORY IS 'This table logs details of workflow executions, including start and end times, and overall workflow status.';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.A_WORKFLOW_HISTORY_KEY IS 'Technical key to identify a load operation. Generated with Oracle sequence "CT_MRDS.SEQ_WORKFLOW_HISTORY"';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.ORCHESTRATION_RUN_ID IS 'Unique identifier for the orchestration run';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.WORKFLOW_NAME IS 'The name of the workflow';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.WORKFLOW_START IS 'Start time of the Airflow / Informatica workflow';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.WORKFLOW_END IS 'End time of the Airflow / Informatica workflow';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.WORKFLOW_SUCCESSFUL IS 'Overall status of the workflow. Allowed values are ''R'' (running), ''Y'' (yes), and ''N'' (no)';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.DBT_INVOCATION_ID IS 'Unique identifier for the DBT invocation';
COMMENT ON COLUMN CT_MRDS.A_WORKFLOW_HISTORY.SERVICE_NAME IS 'Filter for the service: RAR, MOPDB, ODS';



CREATE TABLE "CT_MRDS"."A_DEVO_REPLICA_MGMT_MOPDB" AS
SELECT OWNER, 
    TABLE_NAME, 
    TABLE_ALIAS, 
    CAST(NULL AS VARCHAR2(200)) AS LAST_RUN_ID,
    CAST(NULL AS DATE) AS LAST_START_TIME,
    CAST(NULL AS DATE) AS LAST_END_TIME,
    CAST(NULL AS VARCHAR2(200)) AS LAST_STATUS, 
    SAVE_MODE,
    BUCKET_COLUMN AS PARTITION_COLUMN, 
    NUMBER_OF_BUCKETS AS MAX_THREADS,
    CAST(NULL AS NUMBER(28,10)) AS LAST_PROCESSED_KEY
FROM CT_MOPDB.MOPDB_ON_DISC_REPLICA_MGMT;

CREATE TABLE "CT_MRDS"."A_DEVO_REPLICA_MGMT_RAR" AS
SELECT OWNER, 
    TABLE_NAME, 
    TABLE_ALIAS, 
    CAST(NULL AS VARCHAR2(200)) AS LAST_RUN_ID,
    CAST(NULL AS DATE) AS LAST_START_TIME,
    CAST(NULL AS DATE) AS LAST_END_TIME,
    CAST(NULL AS VARCHAR2(200)) AS LAST_STATUS, 
    SAVE_MODE,
    BUCKET_COLUMN AS PARTITION_COLUMN, 
    NUMBER_OF_BUCKETS AS MAX_THREADS,
    CAST(NULL AS NUMBER(28,10)) AS LAST_PROCESSED_KEY
FROM CT_REF.RAR_ON_DISC_REPLICA_MGMT;

CREATE TABLE "CT_MRDS"."ERR_LOG" 
   ("ERR_LOG_KEY" NUMBER(*,0), 
	"A_WORKFLOW_HISTORY_KEY" NUMBER(38,0), 
	"ERR_MESSAGE_FK" NUMBER, 
	"ERR_SEVERITY_FK" NUMBER, 
	"ERR_WORKFLOW_RUN_ID" CHAR(17 BYTE) COLLATE "USING_NLS_COMP", 
	"ERR_WORKFLOW_NAME" CHAR(18 BYTE) COLLATE "USING_NLS_COMP", 
	"ERR_MAPPING_NAME" CHAR(74 BYTE) COLLATE "USING_NLS_COMP", 
	"ERR_LOCATION" CHAR(74 BYTE) COLLATE "USING_NLS_COMP", 
	"ERR_SOURCE" CHAR(22 BYTE) COLLATE "USING_NLS_COMP", 
	"ERR_KEY_BUSINESS" CHAR(6 BYTE) COLLATE "USING_NLS_COMP", 
	"ERR_KEY_BUSINESS_VALUE" CHAR(14 BYTE) COLLATE "USING_NLS_COMP", 
	"ERR_KEY_TECHNICAL" CHAR(22 BYTE) COLLATE "USING_NLS_COMP", 
	"ERR_KEY_TECHNICAL_VALUE" VARCHAR2(40 BYTE) COLLATE "USING_NLS_COMP", 
	"ERR_DESCRIPTION" CHAR(94 BYTE) COLLATE "USING_NLS_COMP", 
	"ERR_MESSAGE" VARCHAR2(255 BYTE) COLLATE "USING_NLS_COMP", 
	"INDEP_SUBPROCESS_FK" NUMBER(38,0)
    );


UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_CEPH';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'MPEC' AND TABLE_NAME = 'T_MPEC';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'REFERENCE' AND TABLE_NAME = 'T_CAPITAL_KEY';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'CT_MOPDB' AND TABLE_NAME = 'MOPDB_METADATA_INVENTORY';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'REFERENCE' AND TABLE_NAME = 'T_CSDB_RATING_ACTION';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'REFERENCE' AND TABLE_NAME = 'T_CURRENCY';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'CLSLNK_SNPSHT_DT' WHERE OWNER = 'RIAD' AND TABLE_NAME = 'T_CLSLNK_PSTNZ_HIST';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'TOP' AND TABLE_NAME = 'T_AGGREGATED_ALLOTMENT';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'ELA' AND TABLE_NAME = 'T_ELA_INFO';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_ALL_ASSETS_ORIGINATOR';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_ALL_ASSETS_ADD_GUARANTOR';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_ALL_ASSETS_IAB';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_ALL_ASSETS_SERVICER';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_ALL_ASSETS_LSP';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_ALL_ASSETS_IRSP';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_ALL_ASSETS_FXSC';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_COLLATERAL';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'REFERENCE' AND TABLE_NAME = 'T_COUNTRY';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_SNAPSHOT_DATE';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'TOP' AND TABLE_NAME = 'T_ALLOTMENT';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'TOP' AND TABLE_NAME = 'T_ALLOTMENT_MODIFICATIONS';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'TOP' AND TABLE_NAME = 'T_ANNOUNCEMENT';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'TOP' AND TABLE_NAME = 'T_FBL_ITEM';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'TOP' AND TABLE_NAME = 'T_FULLBID_ARRAY_COMPILED';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'REF_DATE' WHERE OWNER = 'LM' AND TABLE_NAME = 'T_STANDING_FACILITIES';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'REFERENCE_DATE' WHERE OWNER = 'LM' AND TABLE_NAME = 'T_CURRENT_ACCOUNTS';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'REF_DATE' WHERE OWNER = 'LM' AND TABLE_NAME = 'T_BALANCE_SHEET';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'REFERENCE_DATE' WHERE OWNER = 'LM' AND TABLE_NAME = 'T_FORECAST';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'ADJUSTMENT_DATE' WHERE OWNER = 'LM' AND TABLE_NAME = 'T_FC_ADH_ADJUSTMENTS';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'LM' AND TABLE_NAME = 'T_FC_CSM_ADJUSTMENTS';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'LM' AND TABLE_NAME = 'T_FC_QRE_ADJUSTMENTS';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_COLLATERAL_ALL_SOURCES';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_ALL_ASSETS';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'TIME_PERIOD' WHERE OWNER = 'SDW' AND TABLE_NAME = 'T_EXCHANGE_RATES';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'OVERWRITE', PARTITION_COLUMN = 'ROWID' WHERE OWNER = 'TOP' AND TABLE_NAME = 'T_ALLOTMENT_MODIFICATIONS_AGGREGATED';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'T_INTRADAY_CREDIT';
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_MOPDB SET SAVE_MODE = 'APPEND', PARTITION_COLUMN = 'SNAPSHOT_DATE' WHERE OWNER = 'C2D' AND TABLE_NAME = 'MV_PUBLIC_ELIGIBLE_MARKETABLE_ASSETS';
commit;


UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_RAR
SET SAVE_MODE = 'OVERWRITE' , PARTITION_COLUMN = 'ROWID';
commit;

UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_RAR SET SAVE_MODE = 'APPEND' , PARTITION_COLUMN = 'A_SNAPSHOT_DATE' WHERE TABLE_NAME = 'NH_HF_PRICE' AND OWNER = 'CORR_RAR' ;
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_RAR SET SAVE_MODE = 'APPEND' , PARTITION_COLUMN = 'A_INSERTION_DATE' WHERE TABLE_NAME = 'NH_PRICE' AND OWNER = 'CORR_RAR' ;
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_RAR SET SAVE_MODE = 'APPEND' , PARTITION_COLUMN = 'A_INSERTION_DATE' WHERE TABLE_NAME = 'NH_POSITION' AND OWNER = 'CORR_RAR' ;
UPDATE CT_MRDS.A_DEVO_REPLICA_MGMT_RAR SET SAVE_MODE = 'APPEND' , PARTITION_COLUMN = 'A_INSERTION_DATE' WHERE TABLE_NAME = 'NH_PERFORMANCE' AND OWNER = 'CORR_RAR' ;

commit;
	
---------------------
------ SEQUENCES ----
---------------------

DECLARE
    start_val NUMBER; -- Variable to hold the maximum value from the table
BEGIN
    -- Create A_TASK_HISTORY_KEY_SEQ
    EXECUTE IMMEDIATE 'CREATE SEQUENCE CT_MRDS.A_TASK_HISTORY_KEY_SEQ MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 10000000 CACHE 20 NOORDER NOCYCLE NOKEEP NOSCALE GLOBAL';

    -- Create A_TASK_HISTORY_SOURCE_KEY_SEQ
    EXECUTE IMMEDIATE 'CREATE SEQUENCE CT_MRDS.A_TASK_HISTORY_SOURCE_KEY_SEQ MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 10000000 CACHE 20 NOORDER NOCYCLE NOKEEP NOSCALE GLOBAL';

    -- Create A_TASK_HISTORY_TARGET_KEY_SEQ
    EXECUTE IMMEDIATE 'CREATE SEQUENCE CT_MRDS.A_TASK_HISTORY_TARGET_KEY_SEQ MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 10000000 CACHE 20 NOORDER NOCYCLE NOKEEP NOSCALE GLOBAL';

    -- Create A_WORKFLOW_HISTORY_KEY_SEQ
    EXECUTE IMMEDIATE 'CREATE SEQUENCE CT_MRDS.A_WORKFLOW_HISTORY_KEY_SEQ MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 10000000 CACHE 20 NOORDER NOCYCLE NOKEEP NOSCALE GLOBAL';
END;
