@echo off

if "%1"=="" goto :usage
if "%2"=="" goto :usage
if "%3"=="" goto :usage
if "%4"=="" goto :usage
if "%5"=="" goto :usage

@echo Install Schema
sqlplus /nolog @Schema\InstallMIP %1 %2 %3 %4 %5 %6

if "%6"=="" goto :not_associate

@echo Associate Schema
sqlplus /nolog @Schema\InstallAssociateSchema.sql %1 %2 %3 %4 %5 %6

:not_associate

@echo Install Seed
cd Data\Seed
call InstallSeed %3/%4@%5
cd ..\..
@echo Seed Complete


@echo Install Modules
sqlplus %3/%4@%5 @Modules\Modules.sql
@echo Modules Complete


sqlplus %3/%4@%5 @Data\Seed\create_passwords.sql


if "%6"=="" goto :done
if "%6"=="demo" goto :demo
if "%6"=="test" goto :test
if "%6"=="fat" goto :fat
if "%6"=="sat" goto :sat
if "%6"=="uat" goto :uat
if "%6"=="live" goto :live
if "%6"=="train" goto :train
if "%6"=="dev" goto :bulkload


:demo
@echo Demo
cd Data\Demo
call InstallData %3/%4@%5
cd ..\..
@echo Demo Complete

goto :bulkload

:test
@echo Install Test data
cd Data\test
call InstallData %3/%4@%5
@echo Installed Test data
@echo Installing Test application in APEX...
ruby apex_auto_install.rb %3
cd ..\..

@echo Test Complete

goto :bulkload

:fat
@echo Install FAT data
cd Data\fat
call InstallData %3/%4@%5
@echo Installed fat data
@echo Installing fat application in APEX...
ruby apex_auto_install.rb %3
cd ..\..

@echo fat install Complete

goto :bulkload

:sat
@echo Install SAT data
cd Data\sat
call InstallData %3/%4@%5
@echo Installed sat data
@echo Installing sat application in APEX...
ruby apex_auto_install.rb %3
cd ..\..

@echo sat install Complete

goto :bulkload

:train
@echo Training Data uses UAT data
goto :uat

:uat
@echo Install UAT data
cd Data\uat
call InstallData %3/%4@%5
@echo Installed uat data
cd ..\..

@echo uat install Complete

goto :bulkload

:live
@echo Install live data
cd Data\live
call InstallData %3/%4@%5
@echo Installed live data
cd ..\..

@echo live install Complete

goto :bulkload

:bulkload

@echo Perform Bulk Load
sqlplus %3/%4@%5 @Data\BulkLoad\bulk_load.sql "%6"


if "%6"=="" goto :not_substitution

@echo Set Substitution Strings
sqlplus /nolog @Schema\InstallSetSubstitution.sql %1 %2 %3 %4 %5 %6
goto :done

:not_substitution
@echo NO substitutions performed

goto :done

:usage
echo "usage	InstallMIP sys_name sys_password app_name app_password db_connect_string [dev|demo|test|fat|sat|uat|train|live]"

:done
@echo DONE!
