diff --git a/backend/manager/dbscripts/create_db.sh b/backend/manager/dbscripts/create_db.sh index 6508738..d1a48e7 100755 --- a/backend/manager/dbscripts/create_db.sh +++ b/backend/manager/dbscripts/create_db.sh @@ -1,7 +1,8 @@ #!/bin/bash #include db general functions -source ./dbfunctions.sh -source ./dbcustomfunctions.sh +HERE="$(cd "$(dirname "$0}")" && pwd)" +source $HERE/dbfunctions.sh +source $HERE/dbcustomfunctions.sh #setting defaults set_defaults @@ -41,8 +42,10 @@ done printf "Creating the database: ${DATABASE}\n" #try to drop the database first (if exists) -dropdb --username=${USERNAME} --host=${SERVERNAME} ${DATABASE} -e > /dev/null -createdb --username=${USERNAME} --host=${SERVERNAME} ${DATABASE} -e -E UTF8 > /dev/null +#dropdb --username=${USERNAME} --host=${SERVERNAME} ${DATABASE} -e > /dev/null +#createdb --username=${USERNAME} --host=${SERVERNAME} ${DATABASE} -e -E UTF8 > /dev/null +dropdb --username=${USERNAME} ${DATABASE} -e > /dev/null +createdb --username=${USERNAME} ${DATABASE} -e -E UTF8 > /dev/null if [ $? -ne 0 ] then printf "Failed to create database ${DATABASE}\n" @@ -59,13 +62,13 @@ echo user name is: ${USERNAME} check_and_install_uuid_osspa ${UUID} printf "Creating tables...\n" -execute_file "create_tables.sql" ${DATABASE} > /dev/null +execute_file "$HERE/create_tables.sql" ${DATABASE} > /dev/null printf "Creating functions...\n" -execute_file "create_functions.sql" ${DATABASE} > /dev/null +execute_file "$HERE/create_functions.sql" ${DATABASE} > /dev/null printf "Creating common functions...\n" -execute_file "common_sp.sql" ${DATABASE} > /dev/null +execute_file "$HERE/common_sp.sql" ${DATABASE} > /dev/null #inserting initial data insert_initial_data @@ -75,12 +78,12 @@ printf "Running upgrade scripts...\n" run_upgrade_files printf "Creating views...\n" -execute_file "create_views.sql" ${DATABASE} > /dev/null +execute_file "$HERE/create_views.sql" ${DATABASE} > /dev/null printf "Creating stored procedures...\n" -for sql in $(ls *sp.sql); do +for sql in $(ls $HERE/*sp.sql); do printf "creating stored procedures from $sql ...\n" execute_file $sql ${DATABASE} > /dev/null done diff --git a/backend/manager/dbscripts/create_db_devel.sh b/backend/manager/dbscripts/create_db_devel.sh index 341ef3c..fc339b3 100755 --- a/backend/manager/dbscripts/create_db_devel.sh +++ b/backend/manager/dbscripts/create_db_devel.sh @@ -1,6 +1,7 @@ #!/bin/bash #include db general functions -source ./dbfunctions.sh +HERE="$(cd "$(dirname "$0}")" && pwd)" +source $HERE/dbfunctions.sh SERVERNAME="127.0.0.1" DATABASE="engine" @@ -19,14 +20,14 @@ while getopts :hs:d:u:p:l:f:v option; do done printf "Running original create_db script...\n" -./create_db.sh -s $SERVERNAME -d $DATABASE -u $USERNAME -f $UUID; +$HERE/create_db.sh -s $SERVERNAME -d $DATABASE -u $USERNAME -f $UUID; if [ $? -ne 0 ] then printf "Failed to create database ${DATABASE}\n" exit 1; fi printf "Setting development configuration values ...\n" -execute_file "fill_config_devel.sql" ${DATABASE} > /dev/null +execute_file "$HERE/fill_config_devel.sql" ${DATABASE} > /dev/null ret=$? printf "Development setting done.\n" exit $? diff --git a/backend/manager/dbscripts/dbcustomfunctions.sh b/backend/manager/dbscripts/dbcustomfunctions.sh index dde6cc5..b5a4a1e 100755 --- a/backend/manager/dbscripts/dbcustomfunctions.sh +++ b/backend/manager/dbscripts/dbcustomfunctions.sh @@ -1,12 +1,14 @@ #!/bin/bash +HERE="$(cd "$(dirname "$0}")" && pwd)" + insert_initial_data() { printf "Inserting data ...\n" - execute_file "insert_data.sql" ${DATABASE} > /dev/null + execute_file "$HERE/insert_data.sql" ${DATABASE} > /dev/null printf "Inserting configuration ...\n" - execute_file "fill_config.sql" ${DATABASE} > /dev/null + execute_file "$HERE/fill_config.sql" ${DATABASE} > /dev/null printf "Inserting pre-defined roles ...\n" - execute_file "insert_predefined_roles.sql" ${DATABASE} > /dev/null + execute_file "$HERE/insert_predefined_roles.sql" ${DATABASE} > /dev/null } set_defaults() { diff --git a/backend/manager/dbscripts/dbfunctions.sh b/backend/manager/dbscripts/dbfunctions.sh index 3cf8f8f..ecf2840 100755 --- a/backend/manager/dbscripts/dbfunctions.sh +++ b/backend/manager/dbscripts/dbfunctions.sh @@ -1,5 +1,7 @@ #!/bin/bash +HERE="$(cd "$(dirname "$0}")" && pwd)" + # $1 - the command to execute # $2 - the database to use execute_command () { @@ -52,49 +54,49 @@ execute_file () { #drops views before upgrade or refresh operations drop_views() { # common stored procedures are executed first (for new added functions to be valid) -execute_file "common_sp.sql" ${DATABASE} > /dev/null +execute_file "$HERE/common_sp.sql" ${DATABASE} > /dev/null printf "Dropping all existing views ...\n" CMD="select * from generate_drop_all_views_syntax();" execute_command "$CMD" ${DATABASE} > drop_all_views.sql - execute_file "drop_all_views.sql" ${DATABASE} > /dev/null + execute_file "$HERE/drop_all_views.sql" ${DATABASE} > /dev/null \rm -f drop_all_views.sql } #drops sps before upgrade or refresh operations drop_sps() { # common stored procedures are executed first (for new added functions to be valid) -execute_file "common_sp.sql" ${DATABASE} > /dev/null +execute_file "$HERE/common_sp.sql" ${DATABASE} > /dev/null printf "Dropping all existing stored procedures ...\n" CMD="select * from generate_drop_all_functions_syntax();" execute_command "$CMD" ${DATABASE} > drop_all_functions.sql - execute_file "drop_all_functions.sql" ${DATABASE} > /dev/null + execute_file "$HERE/drop_all_functions.sql" ${DATABASE} > /dev/null \rm -f drop_all_functions.sql # recreate generic functions - execute_file "create_functions.sql" ${DATABASE} > /dev/null + execute_file "$HERE/create_functions.sql" ${DATABASE} > /dev/null } #refreshes views refresh_views() { printf "Refreshing views...\n" - execute_file "create_views.sql" ${DATABASE} > /dev/null + execute_file "$HERE/create_views.sql" ${DATABASE} > /dev/null } #refreshes sps refresh_sps() { printf "Refreshing the stored procedures...\n" - for sql in $(ls *sp.sql); do + for sql in $(ls $HERE/*sp.sql); do printf "Refreshing stored procedures from $sql ...\n" execute_file $sql ${DATABASE} > /dev/null done - execute_file "common_sp.sql" ${DATABASE} > /dev/null + execute_file "$HERE/common_sp.sql" ${DATABASE} > /dev/null } #run upgrade files run_upgrade_files() { - res=$(find upgrade/ -name "*.sql" | wc -l) + res=$(find $HERE/upgrade/ -name "*.sql" | wc -l) if [ $res -gt 0 ]; then - for upgradeFile in $(ls upgrade/*.sql); do + for upgradeFile in $(ls $HERE/upgrade/*.sql); do printf "Running upgrade script $upgradeFile ...\n" execute_file $upgradeFile ${DATABASE} > /dev/null done diff --git a/backend/manager/dbscripts/refreshStoredProcedures.sh b/backend/manager/dbscripts/refreshStoredProcedures.sh index dd3e66f..c2ae0bb 100755 --- a/backend/manager/dbscripts/refreshStoredProcedures.sh +++ b/backend/manager/dbscripts/refreshStoredProcedures.sh @@ -1,7 +1,9 @@ #!/bin/bash + #include db general functions -source ./dbfunctions.sh -source ./dbcustomfunctions.sh +HERE="$(cd "$(dirname "$0}")" && pwd)" +source $HERE/dbfunctions.sh +source $HERE/dbcustomfunctions.sh #setting defaults set_defaults diff --git a/backend/manager/dbscripts/upgrade.sh b/backend/manager/dbscripts/upgrade.sh index 856271f..adc8409 100755 --- a/backend/manager/dbscripts/upgrade.sh +++ b/backend/manager/dbscripts/upgrade.sh @@ -17,11 +17,12 @@ ################################################################################ #include db general functions -if [ -e ./dbfunctions.sh ]; then - source ./dbfunctions.sh - source ./dbcustomfunctions.sh +HERE="$(cd "$(dirname "$0}")" && pwd)" +if [ -e $HERE/dbfunctions.sh ]; then + source $HERE/dbfunctions.sh + source $HERE/dbcustomfunctions.sh else - printf "upgrade script should be run from database scripts directory\n" + printf "upgrade script could not find dbfunctions.sh\n" exit 1 fi @@ -64,7 +65,7 @@ drop_views drop_sps # common stored procedures are executed first (for new added functions to be valid) -execute_file "common_sp.sql" ${DATABASE} > /dev/null +execute_file "$HERE/common_sp.sql" ${DATABASE} > /dev/null printf "Upgrading database ...\n" run_upgrade_files