drop function if exists staging2.run_master_wrapper; CREATE OR REPLACE FUNCTION staging2.run_master_wrapper() RETURNS void AS $$ declare f record; stg2_status text; error_sum int; err_file_syspk int; TRX_status text; begin for f in select distinct file_syspk,file_mnemonic,file_sheet_mnemonic,client_id,function_id from fw_core.fw_jobctl_file_sheet_runschedule where file_sheet_mnemonic !='' and latest_run_schedule_flag = 1 and end_status != 'error' and end_status_note = 'stg1_completed'--and file_mnemonic not in ('DBOECD','IHTSLL','IHT') order by file_syspk loop if err_file_syspk = f.file_syspk then --incase of file stg2/trx fail then dont run script for those files and rollback previous change if any. --rollback for that file syspk needs to be added continue; else --run staging 2 scripts depending on sheet mnemonic if f.file_sheet_mnemonic = 'FTDRY_TRS' then perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_TRS_Block('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'FTDRY_SUM' then perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_SUM_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'FTWET_TRS' then perform fw_core.fn_get_function_exception('staging2.fn_ftwet_trs_block('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'FTWET_SUM' then perform fw_core.fn_get_function_exception('staging2.fn_FTWET_SUM_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'FTHLG_TRS' then perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_TRS_Block('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'FTHLG_SUM' then perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_SUM_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'DBSTD_TEST' then perform fw_core.fn_get_function_exception('staging2.fn_dbstd_test_block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'DBOECD_TEST' then perform fw_core.fn_get_function_exception('staging2.fn_dboecd_test_block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic in ('PTOBEN_PRFN','PTOBEN_PRFE','PTOBEN_PRFB','PTOSTD_PRF') then perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic in ('PTOBEN_MPM','PTOSTD_MPM') then perform fw_core.fn_get_function_exception('staging2.fn_PTO_MPM_block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic in ('PTOBEN_GVG','PTOSTD_GVG') then perform fw_core.fn_get_function_exception('staging2.fn_PTO_GVG_block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_BRK' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_BRK_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_FLD' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_FLD_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_HDL' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HDL_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_NMT' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_NMT_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_HLG' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HLG_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_PTO' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_PTO_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_VMT' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_VMT_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_ARC' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_ARC_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_DBP' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_DBP_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_LCG' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_LCG_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTCGM_CGM' then perform fw_core.fn_get_function_exception('staging2.fn_IHTCGM_CGM_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTEMT_STD' then perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_STD_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTEMT_EMT' then perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_EMT_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTHAM_HAM' then perform fw_core.fn_get_function_exception('staging2.fn_IHTHAM_HAM_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTHLS_HLS' then perform fw_core.fn_get_function_exception('staging2.fn_IHTHLS_HLS_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTNST_NST' then perform fw_core.fn_get_function_exception('staging2.fn_IHTNST_NST_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTSLL_SLL' then perform fw_core.fn_get_function_exception('staging2.fn_IHTSLL_SLL_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTBT30_BT30' then perform fw_core.fn_get_function_exception('staging2.fn_IHTBT30_BT30_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTBT50_BT50' then perform fw_core.fn_get_function_exception('staging2.fn_IHTBT50_BT50_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTBTD_BTD' then perform fw_core.fn_get_function_exception('staging2.fn_IHTBTD_BTD_Block ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); else perform fw_core.fn_insert_db_error ( f.function_id, f.function_id, 1001, 'Compegence', f.file_syspk ,f.file_mnemonic,f.file_sheet_mnemonic ,null,'stg2 wrapper', 'unknown block', null, 'no script found', 'Script not present for the particlar sheet mnemonic', null, null,'error'); end if; -- check if staging 2 script ran correctly and update fw_jobctl_file_sheet_runschedule table. select e.status from fw_core.db_run_status e where file_syspk = f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic and staging_type = 'stg2' order by error_timestamp desc into stg2_status; if stg2_status = 'success' then update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'stg2_completed', end_status='success',staging_type = 'stg2',end_time = (select e.error_timestamp from fw_core.db_run_status e where e.file_syspk=f.file_syspk and e.file_sheet_mnemonic =f.file_sheet_mnemonic and e.staging_type = 'stg2' order by e.error_timestamp desc limit 1) where file_syspk=f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic; else update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'stg2_failed', end_status='error',staging_type = 'stg2',end_time = (select e.error_timestamp from fw_core.db_run_status e where e.file_syspk=f.file_syspk and e.file_sheet_mnemonic =f.file_sheet_mnemonic and e.staging_type = 'stg2' order by e.error_timestamp desc limit 1) , error_description = (select e.error_detail from fw_core.db_run_status e where e.file_syspk=f.file_syspk and e.file_sheet_mnemonic =f.file_sheet_mnemonic and e.staging_type = 'stg2' order by e.error_timestamp desc limit 1) where file_syspk=f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic; --if error occured store in err_file_syspk variable and go to next file in loop err_file_syspk := f.file_syspk; continue; end if; --run transactional scripts depending on sheet mnemonic if f.file_sheet_mnemonic = 'FTDRY_TRS' then perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_TRS_TRX('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'FTDRY_SUM' then perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_SUM_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'FTWET_TRS' then perform fw_core.fn_get_function_exception('staging2.fn_ftwet_trs_TRX('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'FTWET_SUM' then perform fw_core.fn_get_function_exception('staging2.fn_FTWET_SUM_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'FTHLG_TRS' then perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_TRS_TRX('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'FTHLG_SUM' then perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_SUM_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'DBSTD_TEST' then perform fw_core.fn_get_function_exception('staging2.fn_dbstd_test_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'DBOECD_TEST' then perform fw_core.fn_get_function_exception('staging2.fn_dboecd_test_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic in ('PTOBEN_PRFN','PTOBEN_PRFE','PTOBEN_PRFB','PTOSTD_PRF') then perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic in ('PTOBEN_MPM','PTOSTD_MPM') then perform fw_core.fn_get_function_exception('staging2.fn_PTO_MPM_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic in ('PTOBEN_GVG','PTOSTD_GVG') then perform fw_core.fn_get_function_exception('staging2.fn_PTO_GVG_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_BRK' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_BRK_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_FLD' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_FLD_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_HDL' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HDL_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_NMT' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_NMT_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_HLG' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HLG_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_PTO' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_PTO_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_VMT' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_VMT_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_ARC' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_ARC_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_DBP' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_DBP_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'BUDNI_LCG' then perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_LCG_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTCGM_CGM' then perform fw_core.fn_get_function_exception('staging2.fn_IHTCGM_CGM_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTEMT_STD' then perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_STD_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTEMT_EMT' then perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_EMT_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTHAM_HAM' then perform fw_core.fn_get_function_exception('staging2.fn_IHTHAM_HAM_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTHLS_HLS' then perform fw_core.fn_get_function_exception('staging2.fn_IHTHLS_HLS_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTNST_NST' then perform fw_core.fn_get_function_exception('staging2.fn_IHTNST_NST_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTSLL_SLL' then perform fw_core.fn_get_function_exception('staging2.fn_IHTSLL_SLL_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTBT30_BT30' then perform fw_core.fn_get_function_exception('staging2.fn_IHTBT30_BT30_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTBT50_BT50' then perform fw_core.fn_get_function_exception('staging2.fn_IHTBT50_BT50_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); elsif f.file_sheet_mnemonic = 'IHTBTD_BTD' then perform fw_core.fn_get_function_exception('staging2.fn_IHTBTD_BTD_TRX ('||f.client_id||','||f.function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); else perform fw_core.fn_insert_db_error ( f.function_id, f.function_id, 1001, 'Compegence', f.file_syspk ,f.file_mnemonic, f.file_sheet_mnemonic ,null,'TRX wrapper', 'unknown TRX', null, 'no script found', null, null, null,'error'); end if; -- check if transactional script ran correctly and update fw_jobctl_file_sheet_runschedule table. select e.status from fw_core.db_run_status e where file_syspk = f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic and staging_type = 'trx' order by error_timestamp desc into TRX_status; if TRX_status = 'success' then update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'TRX_completed', end_status='success',staging_type = 'trx',end_time = (select e.error_timestamp from fw_core.db_run_status e where e.file_syspk=f.file_syspk and e.file_sheet_mnemonic =f.file_sheet_mnemonic and e.staging_type = 'trx' order by e.error_timestamp desc limit 1) where file_syspk=f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic; else update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'TRX_failed', end_status='error',staging_type = 'trx',end_time = (select e.error_timestamp from fw_core.db_run_status e where e.file_syspk=f.file_syspk and e.file_sheet_mnemonic =f.file_sheet_mnemonic and e.staging_type = 'trx' order by e.error_timestamp desc limit 1) , error_description = (select e.error_detail from fw_core.db_run_status e where e.file_syspk=f.file_syspk and e.file_sheet_mnemonic =f.file_sheet_mnemonic and e.staging_type = 'trx' order by e.error_timestamp desc limit 1) where file_syspk=f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic; --if error occured store in err_file_syspk variable and go to next file in loop err_file_syspk := f.file_syspk; continue; end if; end if; end loop; -- update fw_jobctl_file_runschedule table. update fw_core.fw_jobctl_file_runschedule set end_status_note = 'stg2_failed', end_status='error',staging_type = 'stg2' from fw_core.fw_jobctl_file_sheet_runschedule a where a.latest_run_schedule_flag = 1 and a.end_status = 'error' and a.end_status_note = 'stg2_failed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk; update fw_core.fw_jobctl_file_runschedule set end_status_note = 'TRX_failed', end_status='error',staging_type = 'trx' from fw_core.fw_jobctl_file_sheet_runschedule a where a.latest_run_schedule_flag = 1 and a.end_status = 'error' and a.end_status_note = 'TRX_failed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk; update fw_core.fw_jobctl_file_runschedule set end_status_note = 'TRX_completed', end_status='success',staging_type = 'trx' from fw_core.fw_jobctl_file_sheet_runschedule a where a.latest_run_schedule_flag = 1 and a.end_status = 'success' and a.end_status_note ='TRX_completed' and fw_core.fw_jobctl_file_runschedule.end_status !='error' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk; -- update fw_jobctl_runschedule_jobstep table. SELECT SUM (case WHEN end_status = 'success' THEN 0 ELSE 1 END) AS "Error Sum" FROM fw_core.fw_jobctl_file_runschedule where latest_run_schedule_flag = 1 INTO error_sum; if error_sum = 0 then update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'run_completed', end_status='success' where latest_run_schedule_flag = true and job_name = 'master load'; else update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'run_failed', end_status='error' where latest_run_schedule_flag = true and job_name = 'master load'; end if; end; $$ LANGUAGE plpgsql; select staging2.run_master_wrapper() --update after each run update fw_core.fw_jobctl_file_runschedule set end_status_note = 'stg1_completed'; update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'stg1_completed'; update fw_core.fw_jobctl_file_runschedule set end_status='success'; update fw_core.fw_jobctl_file_runschedule set staging_type = 'staging1'; update fw_core.fw_jobctl_file_sheet_runschedule set staging_type = 'staging1'; update fw_core.fw_jobctl_file_runschedule set latest_run_schedule_flag = 1; update fw_core.fw_jobctl_file_sheet_runschedule set file_syspk_error_flag='success'; update fw_core.fw_jobctl_file_sheet_runschedule set end_status='success'; update fw_core.fw_jobctl_file_sheet_runschedule set latest_run_schedule_flag = 1; update fw_core.fw_jobctl_file_sheet_runschedule set file_syspk_error_flag = 'success'; update fw_core.fw_jobctl_file_sheet_runschedule set error_description = null; -- changing file sheet mnemonic update fw_core.fw_jobctl_file_sheet_runschedule set file_sheet_mnemonic = 'IHTNST_NST' where file_sheet_mnemonic = 'IHT_NST'; update fw_core.fw_jobctl_file_sheet_runschedule set file_sheet_mnemonic = 'IHTSLL_SLL' where file_sheet_mnemonic = 'IHT_SLL'; update fw_core.fw_jobctl_file_sheet_runschedule set file_sheet_mnemonic = 'IHTHAM_HAM' where file_sheet_mnemonic = 'IHT_HAM'; update fw_core.fw_jobctl_file_sheet_runschedule set file_sheet_mnemonic = 'IHTBRT_BRT' where file_sheet_mnemonic = 'IHT_BRT'; update fw_core.fw_jobctl_file_sheet_runschedule set file_sheet_mnemonic = 'IHTEMT_EMT' where file_sheet_mnemonic = 'IHT_EMT'; update fw_core.fw_jobctl_file_sheet_runschedule set file_sheet_mnemonic = 'IHTHLS_HLS' where file_sheet_mnemonic = 'IHT_HLS'; update fw_core.fw_jobctl_file_sheet_runschedule set file_sheet_mnemonic = 'IHTCGM_CGM' where file_sheet_mnemonic = 'IHT_CGM'; --sheet_runshedule ALTER TABLE fw_core.fw_jobctl_file_sheet_runschedule RENAME COLUMN latest_flag TO latest_run_schedule_flag; alter table fw_core.fw_jobctl_file_sheet_runschedule add column end_status text; alter table fw_core.fw_jobctl_file_sheet_runschedule add column error_description text; alter table fw_core.fw_jobctl_file_sheet_runschedule add column file_syspk_error_flag text; alter table fw_core.fw_jobctl_file_sheet_runschedule add column latest_flag int; update fw_core.fw_jobctl_file_sheet_runschedule set file_syspk_error_flag='success'; update fw_core.fw_jobctl_file_sheet_runschedule set end_status='success'; update fw_core.fw_jobctl_file_sheet_runschedule set latest_run_schedule_flag = 1; update fw_core.fw_jobctl_file_sheet_runschedule set file_syspk_error_flag = 'success'; --file_runshedule ALTER TABLE fw_core.fw_jobctl_file_runschedule RENAME COLUMN latest_flag TO latest_run_schedule_flag; alter table fw_core.fw_jobctl_file_runschedule add column end_status text; alter table fw_core.fw_jobctl_file_runschedule add column latest_flag int; update fw_core.fw_jobctl_file_runschedule set end_status='success'; update fw_core.fw_jobctl_file_runschedule set latest_run_schedule_flag = 1; --jobstep ALTER TABLE fw_core.fw_jobctl_runschedule_jobstep RENAME COLUMN latest_flag TO latest_run_schedule_flag; alter table fw_core.fw_jobctl_runschedule_jobstep add column end_status text; update fw_core.fw_jobctl_runschedule_jobstep set latest_run_schedule_flag = true; insert into fw_core.fw_jobctl_runschedule_jobstep (client_id,function_id,job_name,step_name,end_status, run_schedule_date,run_frequency,job_id,step_id,job_step_run_dependency_seuqence,data_from_date, data_to_date,job_script,job_function_name) values (20,1,'master load','run_master_wrapper','success','31-May-21',1,1,1,1,'31-May-21','31-May-21','',''); delete from fw_core.fw_jobctl_runschedule_jobstep --update trx in staging_type in file_sheet and file_runshedule --change run_success to trx_success