__IF_EXISTS__
SELECT 1
  FROM CI_UT_INSTL_DTL
WHERE SCRIPT_FILE_NAME = 'FW45010_APDATA_UGBUPD-10242_OUAF-36243.SQL'
   AND END_DTTM IS NOT NULL
/
__THEN__
__EXIT__
__ENDIF__

-- Update the Migration Request to be 'CM' if references to it are found.  (Otherwise BP will remove it.)

__IF_EXISTS__
select 1 from F1_MIGR_DATA_ST where MIGR_REQ_CD = 'F1-Mobile'
union
select 1 from F1_MIGR_REQ_INCL_REQ where INCL_MIGR_REQ_CD = 'F1-Mobile'
/

__THEN__
update F1_MIGR_REQ set OWNER_FLG = 'CM' where MIGR_REQ_CD = 'F1-Mobile' and OWNER_FLG <> 'CM'
/
update F1_MIGR_REQ_INCL_REQ set OWNER_FLG = 'CM' where MIGR_REQ_CD = 'F1-Mobile' and OWNER_FLG <> 'CM'
/
update F1_MIGR_REQ_INSTR set OWNER_FLG = 'CM' where MIGR_REQ_CD = 'F1-Mobile' and OWNER_FLG <> 'CM'
/
update F1_MIGR_REQ_INSTR_ENTITY set OWNER_FLG = 'CM' where MIGR_REQ_CD = 'F1-Mobile' and OWNER_FLG <> 'CM'
/
update F1_MIGR_REQ_INSTR_L set OWNER_FLG = 'CM' where MIGR_REQ_CD = 'F1-Mobile' and OWNER_FLG <> 'CM'
/
update F1_MIGR_REQ_L set OWNER_FLG = 'CM' where MIGR_REQ_CD = 'F1-Mobile' and OWNER_FLG <> 'CM'
/
update F1_MIGR_REQ_L set DESCR = DESCR || ' (Deprecated)', DESCRLONG = 'This Migration Request is no longer supported.  It is retained for backward compatibility reasons only. ' || DESCRLONG where MIGR_REQ_CD = 'F1-Mobile' and LANGUAGE_CD = 'ENG' 
/
__ELSE__
__ENDIF__

-- Update the Migration Plan to be 'CM' if references to it are found (besides the base one that is getting removed).  (Otherwise BP will remove it.)

__IF_EXISTS__
select 1 from F1_MIGR_REQ_INSTR where MIGR_PLAN_CD = 'F1-DeploymentType' and MIGR_REQ_CD <> 'F1-Mobile'
union
select 1 from F1_MIGR_TRANS where MIGR_PLAN_CD = 'F1-DeploymentType'
union
select 1 from F1_MIGR_PLAN_INSTR where NXT_MIGR_PLAN_CD = 'F1-DeploymentType'

/

__THEN__
update F1_MIGR_PLAN set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-DeploymentType' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-DeploymentType' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR_ALG set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-DeploymentType' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR_L set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-DeploymentType' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_L set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-DeploymentType' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_L set DESCR = DESCR || ' (Deprecated)', DESCRLONG = 'This Migration Plan is no longer supported.  It is retained for backward compatibility reasons only. ' || DESCRLONG where MIGR_PLAN_CD = 'F1-DeploymentType' and LANGUAGE_CD = 'ENG'
/
update CI_MD_MO_OPT set OWNER_FLG = 'CM' where MAINT_OBJ_OPT_FLG = 'F1DM' and MAINT_OBJ_OPT_VAL = 'F1-DeploymentType' and OWNER_FLG <> 'CM'
/

__ELSE__
__ENDIF__

-- Update the Migration Plan to be 'CM' if references to it are found.  (Otherwise BP will remove it.)

__IF_EXISTS__
select 1 from F1_MIGR_REQ_INSTR where MIGR_PLAN_CD = 'F1-MDTType' and MIGR_REQ_CD <> 'F1-Mobile'
union
select 1 from F1_MIGR_TRANS where MIGR_PLAN_CD = 'F1-MDTType'
union
select 1 from F1_MIGR_PLAN_INSTR where NXT_MIGR_PLAN_CD = 'F1-MDTType' and MIGR_PLAN_CD <> 'F1-DeploymentType'
/
__THEN__
update F1_MIGR_PLAN set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-MDTType' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-MDTType' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR_ALG set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-MDTType' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR_L set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-MDTType' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_L set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-MDTType' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_L set DESCR = DESCR || ' (Deprecated)', DESCRLONG = 'This Migration Plan is no longer supported.  It is retained for backward compatibility reasons only. ' || DESCRLONG where MIGR_PLAN_CD = 'F1-MDTType' and LANGUAGE_CD = 'ENG'
/
update CI_MD_MO_OPT set OWNER_FLG = 'CM' where MAINT_OBJ_OPT_FLG = 'F1DM' and MAINT_OBJ_OPT_VAL = 'F1-MDTType' and OWNER_FLG <> 'CM'
/

__ELSE__
__ENDIF__

-- Update the Migration Plan to be 'CM' if references to it are found.  (Otherwise BP will remove it.)

__IF_EXISTS__
select 1 from F1_MIGR_REQ_INSTR where MIGR_PLAN_CD = 'F1-MobileComponent' and MIGR_REQ_CD <> 'F1-Mobile'
union
select 1 from F1_MIGR_TRANS where MIGR_PLAN_CD = 'F1-MobileComponent' 
union
select 1 from F1_MIGR_PLAN_INSTR where NXT_MIGR_PLAN_CD = 'F1-MobileComponent' 
/

__THEN__
update F1_MIGR_PLAN set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-MobileComponent' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-MobileComponent' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR_ALG set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-MobileComponent' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR_L set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-MobileComponent' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_L set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-MobileComponent' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_L set DESCR = DESCR || ' (Deprecated)', DESCRLONG = 'This Migration Plan is no longer supported.  It is retained for backward compatibility reasons only. ' || DESCRLONG where MIGR_PLAN_CD = 'F1-MobileComponent' and LANGUAGE_CD = 'ENG'
/
update CI_MD_MO_OPT set OWNER_FLG = 'CM' where MAINT_OBJ_OPT_FLG = 'F1DM' and MAINT_OBJ_OPT_VAL = 'F1-MobileComponent' and OWNER_FLG <> 'CM'
/

__ELSE__
__ENDIF__

-- Update the Migration Plan to be 'CM' if references to it are found.  (Otherwise BP will remove it.)

__IF_EXISTS__
select 1 from F1_MIGR_REQ_INSTR where MIGR_PLAN_CD = 'F1-DeploymentPart' and MIGR_REQ_CD <> 'F1-Mobile'
union
select 1 from F1_MIGR_TRANS where MIGR_PLAN_CD = 'F1-DeploymentPart'
union
select 1 from F1_MIGR_PLAN_INSTR where NXT_MIGR_PLAN_CD = 'F1-DeploymentPart' and MIGR_PLAN_CD <> 'F1-DeploymentType'
/

__THEN__
update F1_MIGR_PLAN set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-DeploymentPart' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-DeploymentPart' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR_ALG set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-DeploymentPart' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_INSTR_L set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-DeploymentPart' and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_L set OWNER_FLG = 'CM' where MIGR_PLAN_CD = 'F1-DeploymentPart'  and OWNER_FLG <> 'CM'
/
update F1_MIGR_PLAN_L set DESCR = DESCR || ' (Deprecated)', DESCRLONG = 'This Migration Plan is no longer supported.  It is retained for backward compatibility reasons only. ' || DESCRLONG where MIGR_PLAN_CD = 'F1-DeploymentPart' and LANGUAGE_CD = 'ENG'
/
update CI_MD_MO_OPT set OWNER_FLG = 'CM' where MAINT_OBJ_OPT_FLG = 'F1DM' and MAINT_OBJ_OPT_VAL = 'F1-DeploymentPart' and OWNER_FLG <> 'CM'
/

__ELSE__
__ENDIF__

