--
-- $Id$
--
-- Script containing customer specific sql statements for the AAXX database

DEFINE thisfile = 'AAXX#40683.SQL'
DEFINE dbuser   = '^AA|^ASMS|^GULU|^NMMS|^RABO|^ZKHM'

SET ECHO ON
SET DEFINE ON
COLUMN fcltlogfile NEW_VALUE fcltlogfile NOPRINT;
WHENEVER SQLERROR EXIT;
SELECT adm.scriptspoolfile('&dbuser', '&thisfile') AS fcltlogfile FROM DUAL;
WHENEVER SQLERROR CONTINUE;
SPOOL &fcltlogfile
SET DEFINE OFF

------ payload begin ------

INSERT INTO prs_perslid (prs_perslid_naam, 
                         prs_afdeling_key, 
                         prs_srtperslid_key, 
                         prs_perslid_oslogin, 
                         prs_perslid_nr,
                         prs_perslid_dienstverband)                   
      SELECT 'Afmelder1',
             prs_afdeling_key,
             prs_srtperslid_key,
             '_Afmelder1',
             'NIET WIJZIGEN',
             prs_perslid_dienstverband
        FROM prs_perslid
       WHERE prs_perslid_oslogin = '_FACILITOR'
       AND NOT EXISTS (SELECT * FROM prs_perslid WHERE prs_perslid_naam = 'Afmelder1' AND prs_perslid_verwijder IS NULL);

UPDATE prs_bedrijfadres
SET prs_bedrijfadres_lockuser_key = (SELECT prs_perslid_key FROM prs_perslid WHERE prs_perslid_naam = 'Afmelder1' AND prs_perslid_verwijder IS NULL),
    prs_bedrijfadres_locksecret = COALESCE (prs_bedrijfadres_locksecret, dbms_random.string ('a', 32)),
    prs_bedrijfadres_lockexpire = 30
WHERE prs_bedrijfadres_type = 'O'
AND prs_bedrijfadres_locksecret IS NULL;

------ payload end   ------

SET DEFINE OFF
BEGIN adm.systrackscriptId ('$Id$', 0); END;
/

COMMIT;
SET ECHO OFF
SPOOL OFF
SET DEFINE ON
PROMPT Logfile of this upgrade is: &fcltlogfile