Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion init_qwat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#
# ##########

GNUGETOPT="getopt"
if [[ "$OSTYPE" =~ freebsd* ]] || [[ "$OSTYPE" =~ darwin* ]]; then
GNUGETOPT="/usr/local/bin/getopt"
elif [[ "$OSTYPE" =~ openbsd* ]]; then
GNUGETOPT="gnugetopt"
fi

# Exit on error
set -e

Expand All @@ -27,7 +34,7 @@ EOF

}

ARGS=$(getopt -o p:s:drvn -l "pgservice:,srid:,drop-schema,create-roles,verbose,demo,no-baseline" -- "$@");
ARGS=$(${GNUGETOPT} -o p:s:drvn -l "pgservice:,srid:,drop-schema,create-roles,verbose,demo,no-baseline" -- "$@");
if [ $? -ne 0 ];
then
usage
Expand Down
47 changes: 32 additions & 15 deletions update/upgrade_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LOCALDIRGIVEN=0
LOCALDIR=/home/regis/OSLANDIA/projets_locaux/QWAT/local_update_dir_test/
TMPFILEDUMP=/tmp/qwat_dump
UPGRADE=0
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

RED='\033[0;31m'
GREEN='\033[0;32m'
Expand Down Expand Up @@ -69,14 +70,14 @@ fi

# Get current version in ../system/CURRENT_VERSION.txt
# (git tag forbidden)
VERSION_FILE="../system/CURRENT_VERSION.txt"
VERSION_FILE="${SCRIPTDIR}/../system/CURRENT_VERSION.txt"
if [ ! -f $VERSION_FILE ]; then
echo
printf "${RED}$VERSION_FILE file not found! Aborting${NC}\n"
echo
exit 0
fi
VERSION=$(sed 'r' $VERSION_FILE)
VERSION=$(cat $VERSION_FILE)

# set -- "${POSITIONAL[@]}" # restore positional parameters
echo "Parameters:"
Expand All @@ -94,43 +95,59 @@ echo
if [[ $CLEAN -eq 1 ]]; then
printf "\n${BLUE}Cleaning Option set:${NC}\n\n"

sleep 1s
sleep 1

# Read DB info from pg_service.conf file
DBCOMP_NAME=$(sed -n -e "/^\[qwat_comp]/,/^\[/ p" ~/.pg_service.conf | grep "^dbname" | cut -d"=" -f2)
DBCOMP_USER=$(sed -n -e "/^\[qwat_comp]/,/^\[/ p" ~/.pg_service.conf | grep "^user" | cut -d"=" -f2)
DBCOMP_HOST=$(sed -n -e "/^\[qwat_test]/,/^\[/ p" ~/.pg_service.conf | grep "^host" | cut -d"=" -f2)
DBCOMP_PORT=$(sed -n -e "/^\[qwat_test]/,/^\[/ p" ~/.pg_service.conf | grep "^port" | cut -d"=" -f2)
DBTEST_NAME=$(sed -n -e "/^\[qwat_test]/,/^\[/ p" ~/.pg_service.conf | grep "^dbname" | cut -d"=" -f2)
DBTEST_USER=$(sed -n -e "/^\[qwat_test]/,/^\[/ p" ~/.pg_service.conf | grep "^user" | cut -d"=" -f2)
# TODO get also password, port and host
DBTEST_HOST=$(sed -n -e "/^\[qwat_test]/,/^\[/ p" ~/.pg_service.conf | grep "^host" | cut -d"=" -f2)
DBTEST_PORT=$(sed -n -e "/^\[qwat_test]/,/^\[/ p" ~/.pg_service.conf | grep "^port" | cut -d"=" -f2)

if [ ! -z "$DBCOMP_HOST" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any difference between ! -z and -n?

COMPHOST="-h $DBCOMP_HOST"
fi
if [ ! -z "$DBCOMP_PORT" ]; then
COMPPORT="-p $DBCOMP_PORT"
fi
if [ ! -z "$DBTEST_HOST" ]; then
TESTHOST="-h $DBTEST_HOST"
fi
if [ ! -z "$DBTEST_PORT" ]; then
TESTPORT="-p $DBTEST_PORT"
fi

# Drop test & comp DB
dropdb $DBCOMP_NAME -U $DBCOMP_USER
dropdb $DBCOMP_NAME -U $DBCOMP_USER ${COMPHOST} ${COMPPORT}
printf "\t${GREEN}DB $DBCOMP_NAME dropped${NC}\n"
dropdb $DBTEST_NAME -U $DBTEST_USER
dropdb $DBTEST_NAME -U $DBTEST_USER ${TESTHOST} ${TESTPORT}
printf "\t${GREEN}DB $DBTEST_NAME dropped${NC}\n"

# Create test & comp DB
createdb $DBCOMP_NAME -U $DBCOMP_USER
createdb $DBCOMP_NAME -U $DBCOMP_USER ${COMPHOST} ${COMPPORT}
printf "\t${GREEN}DB $DBCOMP_NAME created${NC}\n"
createdb $DBTEST_NAME -U $DBTEST_USER
createdb $DBTEST_NAME -U $DBTEST_USER ${TESTHOST} ${TESTPORT}
printf "\t${GREEN}DB $DBTEST_NAME created${NC}\n"
fi

# initialize qwat db comparison db
printf "\n${BLUE}Initializing qwat comparison db${NC}\n\n"

sleep 1s
../init_qwat.sh -p qwat_comp -s $SRID -r
sleep 1
${SCRIPTDIR}/../init_qwat.sh -p qwat_comp -s $SRID -r

# add pum metadata to DB using current version
printf "\n${BLUE}PUM baseline on qwat_comp${NC}\n\n"
sleep 1s
sleep 1

pum baseline -p qwat_comp -t qwat_sys.info -d delta/ -b $VERSION

# checks delta files from 1.0 lead to the same version as current version, if yes upgrades
printf "\n${BLUE}Test and upgrade qwat core${NC}\n\n"
sleep 1s
sleep 1

#pum test-and-upgrade -pp qwat_prod -pt qwat_test -pc qwat_comp -t qwat_sys.info -d delta/ -f $TMPFILEDUMP -i columns constraints views sequences indexes triggers functions rules
pum test-and-upgrade -x -pp qwat_prod -pt qwat_test -pc qwat_comp -t qwat_sys.info -d delta/ -f $TMPFILEDUMP -i views rules
Expand All @@ -139,13 +156,13 @@ pum test-and-upgrade -x -pp qwat_prod -pt qwat_test -pc qwat_comp -t qwat_sys.in

# if [[ "$LOCALDIRGIVEN" -eq 1 ]]; then
# printf "\n${BLUE}Upgrade qwat_comp with local directory${NC}\n\n"
# sleep 1s
# sleep 1
#
# pum upgrade -p qwat_comp -t qwat_sys.info -d $LOCALDIR
#
# # display changes
# printf "\n${BLUE}Check differences between prod and test + local delta${NC}\n\n"
# sleep 1s
# sleep 1
#
# pum check -p1 qwat_prod -p2 qwat_comp -i columns constraints views sequences indexes triggers functions rules
#
Expand All @@ -155,7 +172,7 @@ pum test-and-upgrade -x -pp qwat_prod -pt qwat_test -pc qwat_comp -t qwat_sys.in
# if [[ $REPLY =~ ^[Yy]$ ]]
# then
# printf "\n${BLUE}Do the local upgrade${NC}\n\n"
# sleep 1s
# sleep 1
#
# # applies local scripts to qwat_prod
# pum upgrade -p qwat_prod -t qwat_sys.info -d $LOCALDIR
Expand Down