Skip to content
Snippets Groups Projects
Commit caef918c authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: trying to get it work

parent e50e2182
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,6 @@ fi ...@@ -32,7 +32,6 @@ fi
source $UTILSPATH/load_settings.sh source $UTILSPATH/load_settings.sh
source $UTILSPATH/helpers.sh source $UTILSPATH/helpers.sh
echo "no1 $MYSQL_HOST"
INSTALL_SQL_FILE="db_2_0.sql" INSTALL_SQL_FILE="db_2_0.sql"
set -e set -e
...@@ -63,7 +62,7 @@ function _execute_tests () { ...@@ -63,7 +62,7 @@ function _execute_tests () {
for tfile in $TESTS ; do for tfile in $TESTS ; do
echo "Running $tfile" echo "Running $tfile"
echo "----- $tfile -----" >> .TEST_RESULTS echo "----- $tfile -----" >> .TEST_RESULTS
cat $tfile | $MYSQL_CMD $(get_con_args_nodb) --disable-pager --batch --raw --skip-column-names --unbuffered >> .TEST_RESULTS cat $tfile | $MYSQL_CMD $(get_db_args_nodb) --disable-pager --batch --raw --skip-column-names --unbuffered >> .TEST_RESULTS
done; done;
popd popd
...@@ -84,9 +83,9 @@ function _install_unit_test_database () { ...@@ -84,9 +83,9 @@ function _install_unit_test_database () {
fi fi
fi fi
sed "s/db_2_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_con_args_nodb) sed "s/db_2_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_mysql_args_nodb)
# crate test user # create test user
grant grant
# update to latest # update to latest
...@@ -108,7 +107,7 @@ function _setup_mytap() { ...@@ -108,7 +107,7 @@ function _setup_mytap() {
pushd libs > /dev/null pushd libs > /dev/null
unzip -u mytap*.zip > /dev/null unzip -u mytap*.zip > /dev/null
pushd mytap*/ > /dev/null pushd mytap*/ > /dev/null
$MYSQL_CMD $(get_con_args_nodb) < mytap.sql > /dev/null || exit 1 $MYSQL_CMD $(get_mysql_args_nodb) < mytap.sql > /dev/null || exit 1
popd > /dev/null popd > /dev/null
rm -r mytap*/ rm -r mytap*/
popd > /dev/null popd > /dev/null
...@@ -143,18 +142,17 @@ Call 'make drop-$DATABASE_NAME' to delete that database or reconfigure with ...@@ -143,18 +142,17 @@ Call 'make drop-$DATABASE_NAME' to delete that database or reconfigure with
exit 0 exit 0
fi fi
sed "s/db_2_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_con_args_nodb) sed "s/db_2_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_mysql_args_nodb)
} }
# Inserts the dump (arg 1) into the database # Inserts the dump (arg 1) into the database
function restore_db() { function restore_db() {
SQL_FILE="$1" SQL_FILE="$1"
$MYSQL_CMD $(get_con_args) < "$SQL_FILE" $MYSQL_CMD $(get_mysql_args) < "$SQL_FILE"
} }
function test-connection() { function test-connection() {
echo $SQL $MYSQL_CMD $(get_mysql_args_nodb) -e "select 0;"
$MYSQL_CMD $(get_con_args_nodb) -e "select 0;"
} }
# Creates a user and grants it sufficient rights. # Creates a user and grants it sufficient rights.
...@@ -178,7 +176,7 @@ function grant() { ...@@ -178,7 +176,7 @@ function grant() {
if [[ "$1" == "--strict" ]] ; then if [[ "$1" == "--strict" ]] ; then
for host in ${DATABASE_USER_HOST_LIST//,/ } ; do for host in ${DATABASE_USER_HOST_LIST//,/ } ; do
CMD="SELECT COUNT(*) FROM mysql.user WHERE user='${DATABASE_USER}' AND host='${host}';" CMD="SELECT COUNT(*) FROM mysql.user WHERE user='${DATABASE_USER}' AND host='${host}';"
[[ $($MYSQL_CMD $(get_con_args_nodb) -s -N -e "$CMD") == 0 ]] || { [[ $($MYSQL_CMD $(get_mysql_args_nodb) -s -N -e "$CMD") == 0 ]] || {
echo "The user '${DATABASE_USER}@${host}' is already in the database." echo "The user '${DATABASE_USER}@${host}' is already in the database."
echo "Please use another user or delete it, e.g. with" echo "Please use another user or delete it, e.g. with"
echo "'mysql -u ${MYSQL_USER} -p -e \"DROP USER ${DATABASE_USER}@${host};\"'" echo "'mysql -u ${MYSQL_USER} -p -e \"DROP USER ${DATABASE_USER}@${host};\"'"
...@@ -189,7 +187,7 @@ function grant() { ...@@ -189,7 +187,7 @@ function grant() {
for host in ${DATABASE_USER_HOST_LIST//,/ } ; do for host in ${DATABASE_USER_HOST_LIST//,/ } ; do
echo "Granting admin privileges to '$DATABASE_USER'@'$host'" echo "Granting admin privileges to '$DATABASE_USER'@'$host'"
$MYSQL_CMD $(get_con_args_nodb) <<EOF $MYSQL_CMD $(get_mysql_args_nodb) <<EOF
CREATE USER IF NOT EXISTS CREATE USER IF NOT EXISTS
'$DATABASE_USER'@'$host' identified by '$DATABASE_USER_PW'; '$DATABASE_USER'@'$host' identified by '$DATABASE_USER_PW';
GRANT USAGE ON *.* TO '$DATABASE_USER'@'$host'; GRANT USAGE ON *.* TO '$DATABASE_USER'@'$host';
...@@ -203,17 +201,17 @@ EOF ...@@ -203,17 +201,17 @@ EOF
# The first argument to this function is the database that shal be dropped. # The first argument to this function is the database that shal be dropped.
function drop() { function drop() {
DROPDB="$1" DROPDB="$1"
for host in ${DATABASE_USER_HOST_LIST//,/ } ; do #for host in ${DATABASE_USER_HOST_LIST//,/ } ; do
$MYSQL_CMD $(get_con_args_nodb) -e "DROP USER '${DATABASE_USER}'@'${host}';" || true #$MYSQL_CMD $(get_mysql_args_nodb) -e "DROP USER '${DATABASE_USER}'@'${host}';" || true
done #done
"$MYSQLADMIN_CMD" $(get_con_args_nodb) -f drop "$DROPDB" "$MYSQLADMIN_CMD" $(get_mysql_args_nodb) -f drop "$DROPDB"
} }
# Returns 0 or non-zero, depending on whether the database exists already. # Returns 0 or non-zero, depending on whether the database exists already.
# Optional parameter: [DATABASE_NAME], else $DATABASE_NAME is used. # Optional parameter: [DATABASE_NAME], else $DATABASE_NAME is used.
function _db_exists() { function _db_exists() {
$MYSQL_CMD $(get_con_args_nodb) -D "${1-${DATABASE_NAME}}" -e "show tables;" > /dev/null 2>&1 \ $MYSQL_CMD $(get_mysql_args_nodb) -D "${1-${DATABASE_NAME}}" -e "show tables;" > /dev/null 2>&1 \
&& return 0 || return 1 && return 0 || return 1
} }
......
...@@ -19,14 +19,14 @@ ...@@ -19,14 +19,14 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
function dump_table { function dump_table {
$MYSQLDUMP_CMD $(get_con_args_nodb) $DATABASE_NAME $1 \ $MYSQLDUMP_CMD $(get_db_args_nodb) $DATABASE_NAME $1 \
> ${DATABASE_NAME}.${1}.${OLD_VERSION}.dump.sql > ${DATABASE_NAME}.${1}.${OLD_VERSION}.dump.sql
} }
function mysql_execute { function mysql_execute {
#TODO is it meaningful that here always the database user is used???
set +e set +e
echo $MYSQL_CMD $(get_con_args) -e "$1" $MYSQL_CMD $(get_db_args) -e "$1"
$MYSQL_CMD $(get_con_args) -e "$1"
ret=${PIPESTATUS[0]} ret=${PIPESTATUS[0]}
if [ "$ret" -ne 0 ]; then if [ "$ret" -ne 0 ]; then
failure "MYSQL ERROR" failure "MYSQL ERROR"
...@@ -34,15 +34,23 @@ function mysql_execute { ...@@ -34,15 +34,23 @@ function mysql_execute {
set -e set -e
} }
function get_con_args { function get_mysql_args {
echo "$(get_con_args_nodb) --database=$DATABASE_NAME" # if [ "$DATABASE_NAME" = "caosdb" ];then
# echo "WRONGDB"
# exit 1
# fi
echo "$(get_mysql_args_nodb) --database=$DATABASE_NAME"
} }
function get_con_args_nodb { function get_db_args {
if [ "$LOGIN_PATH" ]; then # if [ "$DATABASE_NAME" = "caosdb" ];then
mysql_con_arguments="--login-path=$LOGIN_PATH" # echo "WRONGDB"
mysql_con_arguments="$mysql_con_arguments" # exit 1
else # fi
echo "$(get_db_args_nodb) --database=$DATABASE_NAME"
}
function get_db_args_nodb {
if [ "$DATABASE_USER" ]; then if [ "$DATABASE_USER" ]; then
mysql_con_arguments="--user=$DATABASE_USER" mysql_con_arguments="--user=$DATABASE_USER"
fi fi
...@@ -55,11 +63,31 @@ function get_con_args_nodb { ...@@ -55,11 +63,31 @@ function get_con_args_nodb {
mysql_con_arguments="$mysql_con_arguments --port=$MYSQL_PORT" mysql_con_arguments="$mysql_con_arguments --port=$MYSQL_PORT"
fi fi
fi fi
echo $mysql_con_arguments
}
function get_mysql_args_nodb {
if [ "$LOGIN_PATH" ]; then
mysql_con_arguments="--login-path=$LOGIN_PATH"
else
if [ "$MYSQL_USER" ]; then
mysql_con_arguments="--user=$MYSQL_USER"
fi
if [ "$MYSQL_USER_PASSWORD" ]; then
mysql_con_arguments="$mysql_con_arguments --password=$MYSQL_USER_PASSWORD"
fi
if [[ "$MYSQL_HOST" && ( "$MYSQL_HOST" != "localhost" ) ]]; then
mysql_con_arguments="$mysql_con_arguments --host=$MYSQL_HOST"
if [ "$MYSQL_PORT" ]; then
mysql_con_arguments="$mysql_con_arguments --port=$MYSQL_PORT"
fi
fi
fi fi
echo $mysql_con_arguments echo $mysql_con_arguments
} }
function redo_table { function redo_table {
$MYSQL_CMD $(get_con_args) < ${DATABASE_NAME}.${1}.${OLD_VERSION}.dump.sql $MYSQL_CMD $(get_db_args) < ${DATABASE_NAME}.${1}.${OLD_VERSION}.dump.sql
} }
function success { function success {
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
# load useful functions ####################################################### # load useful functions #######################################################
. $UTILSPATH/helpers.sh . $UTILSPATH/helpers.sh
echo $(get_con_args)
USAGE="$1 [ --env=ENV_FILE ] [ --patch=PATCH ] [ --backupdir=BACKUPDIR ]\n\n" USAGE="$1 [ --env=ENV_FILE ] [ --patch=PATCH ] [ --backupdir=BACKUPDIR ]\n\n"
CMD_OPTIONS=$(cat <<EOF CMD_OPTIONS=$(cat <<EOF
...@@ -111,7 +110,7 @@ fi ...@@ -111,7 +110,7 @@ fi
# @param $1: db version string, e.g. v2.0.0 # @param $1: db version string, e.g. v2.0.0
# @return: 0 on success, 1 on failure # @return: 0 on success, 1 on failure
function check_version { function check_version {
local version=$($MYSQL_CMD $(get_con_args) -B -e "Select CaosDBVersion();") local version=$($MYSQL_CMD $(get_db_args) -B -e "Select CaosDBVersion();")
if [[ "$(echo $version | sed 's/^CaosDBVersion()\s//')" = "$1" ]]; then if [[ "$(echo $version | sed 's/^CaosDBVersion()\s//')" = "$1" ]]; then
return 0 return 0
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment