text: -- If you want to add ASCII Art: https://asciiartgen.now.sh/?style=standard
  -- *** DO NOT MODIFY: HEADER SECTION ***
  clear screen
  
  whenever sqlerror exit sql.sqlcode
  
  -- define - Sets the character used to prefix substitution variables
  set define '^'
  -- verify off prevents the old/new substitution message
  set verify off
  -- feedback - Displays the number of records returned by a script ON=1
  set feedback off
  -- timing - Displays the time that commands take to complete
  set timing off
  -- display dbms_output messages
  set serveroutput on
  -- disables blank lines in code
  set sqlblanklines off;
  
  
  -- Log output of release
  define logname = '' -- Name of the log file
  
  set termout off
  column my_logname new_val logname
  select 'release_log_'||sys_context( 'userenv', 'service_name' )|| '_' || to_char(sysdate, 'YYYY-MM-DD_HH24-MI-SS')||'.log' my_logname from dual;
  -- good to clear column names when done with them
  column my_logname clear
  set termout on
  spool ^logname
  prompt Log File: ^logname
  
  
  
  prompt check DB user is expected user
  declare
  begin
    if user != 'CHANGEME_USERNAME' then
      raise_application_error(-20001, 'Must be run as CHANGEME_USERNAME');
    end if;
  end;
  /
  
  prompt Disable APEX Application(s)
  declare
    c_app_id constant apex_applications.application_id%type := CHANGEME_APPLICATION_ID;
    c_username constant varchar2(30) := user;
  begin
    -- Note: This will NOT work in versions < APEX 18. as apex_session.create_session does not exist until then
    -- If using APEX 5.1 or lower use oos_utils.create_session  (see https://github.com/OraOpenSource/oos-utils/blob/master/docs/oos_util_apex.md#create_session)
    -- To install OOS Utils see: https://github.com/OraOpenSource/oos-utils
    apex_session.create_session (
      p_app_id => c_app_id,
      p_page_id => 1,
      p_username => c_username );
  
    apex_util.set_application_status(
      p_application_id => c_app_id,
      p_application_status => 'UNAVAILABLE',
      p_unavailable_value => 'Scheduled update of application.');
  end;
  /
  
  commit;
  
  -- *** END: HEADER SECTION ***
  
  
  -- *** Release specific tasks ***
  
  @code/_run_release_code.sql
  
  -- *** DO NOT MODIFY BELOW ***
  
  
  -- Views and packages will be automatically referenced between the the "AUTOREPLACE" tags below
  -- Alternatively you can remove these tags and manually list all the packages and views for each release
  -- Examples;
  -- @..packages/pkg_emp.pks
  -- @..views/v_emp.sql
  
  -- AUTOREPLACE_START
  -- AUTOREPLACE_END
  
  
  prompt Invalid objects
  select object_name, object_type
  from user_objects
  where status != 'VALID'
  order by object_name
  ;
  
  
  -- *** DATA ****
  
  
  -- Autogenerated triggers
  -- If you have code to automatically generate triggers this is a good place to run in.
  -- An example of what it might look like:
  
  -- declare
  -- begin
  --   pkg_util.gen_triggers()
  -- end;
  -- /
  
  
  -- Load any re-runnable data scripts
  -- ex: @../data/data_my_table.sql
  
  
  -- This needs to be in place after trigger generation as some triggers follow the generated triggers above
  prompt recompile invalid schema objects
  begin
   dbms_utility.compile_schema(schema => user, compile_all => false);
  end;
  /
  
  -- *** APEX ***
  -- DO NOT REMOVE
  
  PROMPT *** APEX Installation ***
  
  set serveroutput on size unlimited;
  declare
    l_workspace_id apex_workspaces.workspace_id%type;
    l_build_option_id apex_application_build_options.build_option_id%type;
  begin
    select workspace_id
    into l_workspace_id
    from apex_workspaces
    where workspace = upper('CHANGEME_WORKSPACE');
  
    apex_application_install.set_application_id(CHANGEME_APPLICATION_ID);
    apex_application_install.set_schema('CHANGEME_USERNAME');
    apex_application_install.set_workspace_id(l_workspace_id);
    apex_application_install.generate_offset;
  
  end;
  /
  
  @../apex/fCHANGEME_APPLICATION_ID.sql
  
  
  -- Control Build Options (optional)
  -- In some cases you may want to enable / disable various build options for an application depending on the environment
  -- An example is provided below on how to enabled a build option
  PROMPT *** APEX Build option ***
  
  -- set serveroutput on size unlimited;
  -- declare
  --   c_app_id constant apex_applications.application_id%type := CHANGEME_APPLICATION_ID;
  --   c_username constant varchar2(30) := user;
  
  --   l_build_option_id apex_application_build_options.build_option_id%type;
  -- begin
  --   if pkg_environment.is_dev() then
  --     select build_option_id
  --     into l_build_option_id
  --     from apex_application_build_options
  --     where 1=1
  --       and application_id = c_app_id
  --       and build_option_name='DEV_ONLY';
  
  --     -- Session is already active ahead
  --     apex_session.create_session (
  --       p_app_id => c_app_id,
  --       p_page_id => 1,
  --       p_username => c_username );
  
  --     apex_util.set_build_option_status(
  --       p_application_id => c_app_id,
  --       p_id => l_build_option_id,
  --       p_build_status=>'INCLUDE');
  --   end if;
  
  -- end;
  -- /
  
  -- commit;
  
  
  spool off
  exit