/* _up/epilogue.inc
 * Epiloog van update script van Facilitor, to be included in every schema update
 *
 * $Revision$
 * $Id$
 */
COMMIT;

-- Bij een DROP TABLE wordt nogal eens de PURGE vergeten
PURGE RECYCLEBIN;

-- Gedropte systeem UDRs
DELETE
  FROM fac_locale
 WHERE fac_locale_kolomnaam LIKE 'FAC_USRRAP_%'
   AND fac_locale_kolomkeyval NOT IN (SELECT fac_usrrap_key FROM fac_usrrap);

DELETE
  FROM fac_locale
 WHERE fac_locale_kolomnaam  LIKE 'FAC_IMPORT_APP_%'
   AND fac_locale_kolomkeyval NOT IN (SELECT fac_import_app_key FROM fac_import_app);

///////////////////////////// now recreate all views, triggers etc acc to the latest state ///////
#include "recreate.inc"

#ifdef POST_RECREATE
#include POST_RECREATE
#endif

BEGIN
   fac.fac_cleanup;
   adm.fix_mld_t_uitvoertijd();
END;
/

INSERT INTO adm_tracking
    (adm_tracking_name, adm_tracking_revision)
VALUES
    ('Database upgraded', 'DB' || _DBV_STRING);
COMMIT;

/* Report invalid objects, if any */
SET ECHO OFF
SET HEADING OFF
SET LINESIZE 132

// Soms nog niet goed.
// Heel agressief compileren omdat zelfs de dubbele COMPILE_SCHEMA straks niet altijd genoeg is.
ALTER PACKAGE fac COMPILE BODY;
ALTER PACKAGE alg COMPILE BODY;
ALTER PACKAGE mld COMPILE BODY;
ALTER PACKAGE prs COMPILE BODY;
ALTER PACKAGE ins COMPILE BODY;
ALTER PACKAGE res COMPILE BODY;
ALTER PACKAGE bes COMPILE BODY;
ALTER PACKAGE bez COMPILE BODY;
ALTER PACKAGE cnd COMPILE BODY;
ALTER PACKAGE cnt COMPILE BODY;
ALTER PACKAGE fin COMPILE BODY;
ALTER PACKAGE ano COMPILE BODY;
ALTER PACKAGE xml COMPILE BODY;
BEGIN
  DBMS_UTILITY.COMPILE_SCHEMA(USER, FALSE);
  DBMS_UTILITY.COMPILE_SCHEMA(USER, FALSE);
END;
/

SELECT 'Upgrade has completed in ' || ROUND(( dbms_utility.get_time - :update_start )/100) || ' seconds.' FROM DUAL;

PROMPT List of all invalid objects after Facilitor upgrade.
PROMPT Some errors may resolve by running the customer specific script next.
SELECT 'OR'||'A-'||'DB'||_DBV_STRING||' Warning: ' || object_type || ' ' || object_name || ' is ' || status
  FROM user_objects
 WHERE object_type IN ('VIEW', 'TRIGGER', 'PACKAGE', 'PROCEDURE', 'FUNCTION', 'PACKAGE BODY')
   AND status <> 'VALID'
 ORDER BY object_name;

SET HEADING ON
column name format a32
column text format a60
column line format 9999
column pos format 9999
SET HEADING ON
SELECT TYPE, NAME, LINE, POSITION POS, TEXT
  FROM USER_ERRORS
 ORDER BY NAME, TYPE, SEQUENCE;

SET ECHO OFF
SET FEEDBACK OFF
PROMPT ======================================================================
SELECT 'Schema Facilitor@' || USER || ' is now ' || fac.getdbversion() FROM DUAL;
PROMPT
PROMPT Your schema upgrade is ready. Please check the logfile for errors.
PROMPT If in doubt please contact: Facilitor Helpdesk +31 53 4800 700
SET DEFINE ON
PROMPT Logfile of this upgrade is: &fcltlogfile
SPOOL OFF
