Rem  Copyright (c) Oracle Corporation 2014. All Rights Reserved.
Rem
Rem    NAME
Rem      ords_install.sql
Rem
Rem    DESCRIPTION
Rem      Installation for the Oracle REST Data Services (ORDS).
Rem      Do not invoke this script directly.  If you are doing a manual installation, use ords_manual_install.sql
Rem
Rem    NOTES
Rem      Assumes user with SYSDBA privilege is connected.
Rem
Rem    REQUIREMENTS
Rem      - Oracle Database 11.1 or later releases
Rem
Rem    Arguments:
Rem      1  : Default tablespace name for ORDS schema
Rem      2  : Temporary tablespace name for ORDS schema
Rem      3  : ORDS Public User info
Rem      4  : Default tablespace name for ORDS Public User
Rem      5  : Temporary tablespace name for ORDS Public User
Rem      6  : Path of log file (include the forward slash at the end)
Rem
Rem    MODIFIED    (MM/DD/YYYY)
Rem     epaglina    10/07/2015 Added ords_schema_mapping.sql
Rem     epaglina    05/18/2015 Support for Oracle 12c installation for CDB,
Rem                            added _ORACLE_SCRIPT, reorganized pl/sql scripts.
Rem     josmende    05/22/2015 Disabling define for oauth internal installation
Rem     josmende    02/18/2015 Adding ORDS Jobs.
Rem     josmnede    11/20/2014 Switching order of synonym script call and rest user creation
Rem     josmende    09/23/2014 Added ORDS Types.
Rem     josmende    08/22/2014 Added OAUTH packages.
Rem     epaglina    03/14/2014 Prompts for ORDS_METADATA password. Uses ords_database_objects.sql. 
Rem                            Invokes the triggers, packages and public synonyms scripts.
Rem     epaglina    01/28/2014 Created.
Rem
Rem

timing start "ORDS Installation"

set verify off
set termout off
spool off

set define '^'
set termout on

define ORDS_DATATBS  = '^1'
define ORDS_TEMPTBS  = '^2'
define PUB_DATATBS   = '^3'
define PUB_TEMPTBS   = '^4'
define LOGFOLDER     = '^5'
define PUB_PWD       = '^6'

define ORDSSCHEMA   = 'ORDS_METADATA'
define ORDSVERSION  = '3.0.3.351.13.24'

whenever sqlerror exit

column logfilename new_val ORDSLOGFILE
select '^LOGFOLDER' || 'ordsinstall_' || to_char(systimestamp,'YYYY-MM-DD_HH24_MI_SS_FF') || '.log' as logfilename from sys.dual;
spool ^ORDSLOGFILE


prompt ******************************************************
prompt * INFO: Oracle REST Data Services (ORDS) Installation.
prompt ******************************************************

--  Verify the prerequisites. Installation will abort if prerequisites are not met.

@@ords_prereq_env.sql
@@ords_verify_tablespace.sql ^ORDS_DATATBS ^ORDS_TEMPTBS ^PUB_DATATBS ^PUB_TEMPTBS

@@ords_alter_session_script.sql TRUE

-- Create the ORDS schema
@@ords_create_schema.sql ^ORDSSCHEMA ^ORDS_DATATBS ^ORDS_TEMPTBS

-- Create ORDS_PUBLIC_USER
@@ords_create_rest_users.sql ^PUB_PWD ^PUB_DATATBS ^PUB_TEMPTBS

-- Create validate_ords in the SYS schema required for the registry
@@ords_validate.sql

-- Grant privileges to ORDS_METADATA
@@ords_grant_privs.sql ^ORDSSCHEMA

-- Start the registry installation for ORDS
-- @@ords_start_registry.sql 1 ^ORDSSCHEMA

prompt
prompt ******************************************************
prompt * INFO: Creating database objects in Oracle REST Data Services ORDS_METADATA
prompt ******************************************************
timing start "Create DB objects"

@@ords_alter_session_metadata.sql
@@ords_version.sql 1 ^ORDSVERSION
@@ords_database_objects.sql

prompt * INFO: Creating Triggers
@@ords_triggers.sql

prompt * INFO: Creating Types
@@ords_types.sql

@@ords_schema_mapping.sql

prompt * INFO: Creating Package Specifications
@@ords.pls
/
@@ords_internal.pls
/
@@ords_security.pls
/
@@ords_services_internal.pls
/
@@ords_services.pls
/
@@oauth_internal.pls
/
@@oauth.pls
/


prompt * INFO: Creating Package Bodies
set define off
@@ords_internal.plb
/
@@ords_security.plb
/
@@ords_services_internal.plb
/
@@ords_services.plb
/
@@ords.plb
/
@@oauth_internal.plb
/
@@oauth.plb
/
set define '^'

prompt * INFO: Creating Jobs
@@ords_jobs.sql ^ORDSSCHEMA

prompt * INFO: Creating Public Synonyms
@@ords_pub_synonyms_grants.sql


prompt
prompt ******************************************************
prompt INFO: Completed creating database objects
timing stop
prompt ******************************************************

-- Create SEED data 
@@ords_seed.sql

-- Remove temporal privileges
@@ords_rem_temp_privs.sql ^ORDSSCHEMA

prompt * INFO: Validating Installation
@@ords_verify_install.sql


@@ords_alter_session_script FALSE

commit;

prompt
prompt *********************************************************
prompt INFO: Completed Oracle REST Data Services Installation.
timing stop
prompt *********************************************************

spool off
