Skip to content
Snippets Groups Projects
Verified Commit 02a1d47d authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Merge branch 'dev' into f-pov-doc

parents ecd35a21 464a61b1
No related branches found
No related tags found
3 merge requests!27Release v7.0.2,!25DOC, STY: in code documentation and styling for readablility,!11DRAFT: file system cleanup
Pipeline #44799 failed
version: '3.6'
services:
sqldb:
image: mariadb:10.5
volumes:
- type: volume
source: "caosdb-sqldata"
target: /var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: caosdb1234
networks:
# available on port 3306, host name 'sqldb'
- caosnet
ports:
- 3306:3306
# A well-defined network for caosdb
volumes:
caosdb-sqldata:
networks:
caosnet:
driver: bridge
...@@ -17,6 +17,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -17,6 +17,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### ### Fixed ###
* make install: Could not connect to MariaDB in local docker
container
[linkahead-mariadbbackend](https://gitlab.com/linkahead/linkahead-mariadbbackend/-/issues/33)
* Wrong ids in data_type table due to a bug in the `linkahead-server < v0.11.0`
which has been fixed but left broken data. This resulted in server errors
[linkahead-mariadbbackend#34](https://gitlab.com/linkahead/linkahead-mariadbbackend/-/issues/34)
### Security ### ### Security ###
## [7.0.1] - 2023-11-01 ## [7.0.1] - 2023-11-01
......
...@@ -87,6 +87,19 @@ with the then current version of the stored entities. ...@@ -87,6 +87,19 @@ with the then current version of the stored entities.
* Alternatively, to run the tests in a containerized MariaDB instance, run `make test-docker`, * Alternatively, to run the tests in a containerized MariaDB instance, run `make test-docker`,
followed by `make test-docker-stop`. followed by `make test-docker-stop`.
### Running in a Docker Container
You can use `.docker/docker-compose.yml` to start a docker container
(`docker-compose -f .docker/docker-compose.yml up -d`) that runs
mariadb. You need appropriate settings in `.config`:
`MYSQL_OPTS="--protocol=TCP"` and
`DATABASE_USER_HOST_LIST=%,`
After the first start, you need to install the database: `make install`.
Then, you can connect to it with
`mariadb --protocol=TCP -u caosdb -prandom1234 caosdb`.
### Troubleshooting ### Troubleshooting
#### MySQL has failing tests #### MySQL has failing tests
......
...@@ -40,6 +40,12 @@ MYSQL_PORT=3306 ...@@ -40,6 +40,12 @@ MYSQL_PORT=3306
# which will then be used by the CaosDB Server. # which will then be used by the CaosDB Server.
MYSQL_USER=root MYSQL_USER=root
MYSQL_USER_PASSWORD=caosdb1234 MYSQL_USER_PASSWORD=caosdb1234
# Additional options for the connection
# e.g. if you want to connect a dockerized MariaDB at localhost you need to put
# "--protocol=TCP" here because when host=localhost the connection defaults to
# SOCKET.
# MYSQL_OPTS='--protocol=TCP'
MYSQL_OPTS=
# # DATABASE # # DATABASE
# The name of the SQL database. # The name of the SQL database.
......
#!/bin/bash
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Update mysql schema to version v7.0.2
# Patch the broken data_type table (fix id for file references as per
# https://gitlab.com/linkahead/linkahead-server/-/issues/246)
NEW_VERSION="v7.0.2"
OLD_VERSION="v7.0.1"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
mysql_execute "UPDATE data_type SET datatype=17 WHERE datatype=3"
update_version $NEW_VERSION
success
...@@ -56,7 +56,7 @@ function backup() { ...@@ -56,7 +56,7 @@ function backup() {
fi fi
echo "Dumping database $database to $backupfile ..." echo "Dumping database $database to $backupfile ..."
$MYSQLDUMP_CMD $(get_mysql_args_nodb) --opt --default-character-set=utf8 \ $MYSQLDUMP_CMD $(get_db_args_nodb) --opt --default-character-set=utf8 \
--routines "$database" > "$backupfile" --routines "$database" > "$backupfile"
success success
......
...@@ -52,47 +52,25 @@ function mysql_execute_file { ...@@ -52,47 +52,25 @@ function mysql_execute_file {
fi fi
} }
function get_mysql_args {
echo "$(get_mysql_args_nodb) --database=$DATABASE_NAME"
}
function get_db_args { function get_db_args {
echo "$(get_db_args_nodb) --database=$DATABASE_NAME" echo "$(get_db_args_nodb) --database=$DATABASE_NAME"
} }
function get_db_args_nodb { function get_db_args_nodb {
if [ "$DATABASE_USER" ]; then if [ -n "$DATABASE_USER" ]; then
mysql_con_arguments="--user=$DATABASE_USER" mysql_con_arguments="--user=$DATABASE_USER"
fi fi
if [ "$DATABASE_USER_PW" ]; then if [ -n "$DATABASE_USER_PW" ]; then
mysql_con_arguments="$mysql_con_arguments --password=$DATABASE_USER_PW" mysql_con_arguments="$mysql_con_arguments --password=$DATABASE_USER_PW"
fi fi
if [[ "$MYSQL_HOST" && ( "$MYSQL_HOST" != "localhost" ) ]]; then if [ -n "$MYSQL_HOST" ] && [ "$MYSQL_HOST" != "localhost" ]; then
mysql_con_arguments="$mysql_con_arguments --host=$MYSQL_HOST" 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
echo $mysql_con_arguments if [ -n "$MYSQL_PORT" ] && [ "$MYSQL_PORT" != "3306" ]; then
} mysql_con_arguments="$mysql_con_arguments --port=$MYSQL_PORT"
fi
function get_mysql_args_nodb { if [ -n "$MYSQL_OPTS" ] ; then
if [ "$LOGIN_PATH" ]; then mysql_con_arguments="$mysql_con_arguments $MYSQL_OPTS"
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
} }
......
...@@ -65,6 +65,7 @@ export MYSQL_CONFIG_EDITOR_CMD ...@@ -65,6 +65,7 @@ export MYSQL_CONFIG_EDITOR_CMD
export MYSQL_HOST export MYSQL_HOST
export MYSQL_PORT export MYSQL_PORT
export MYSQL_USER export MYSQL_USER
export MYSQL_OPTS
export DATABASE_NAME export DATABASE_NAME
export DATABASE_USER export DATABASE_USER
export DATABASE_USER_PW export DATABASE_USER_PW
......
...@@ -87,7 +87,7 @@ function _install_unit_test_database () { ...@@ -87,7 +87,7 @@ function _install_unit_test_database () {
if _db_exists "$DATABASE_NAME"; then if _db_exists "$DATABASE_NAME"; then
echo "using $DATABASE_NAME" echo "using $DATABASE_NAME"
else else
sed "s/db_5_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_mysql_args_nodb) sed "s/db_5_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_db_args_nodb)
# create test user # create test user
grant grant
...@@ -113,7 +113,7 @@ function _setup_mytap() { ...@@ -113,7 +113,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_mysql_args_nodb) < mytap.sql > /dev/null || exit 1 $MYSQL_CMD $(get_db_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
...@@ -129,14 +129,14 @@ name in your .config file " ...@@ -129,14 +129,14 @@ name in your .config file "
exit 0 exit 0
fi fi
sed "s/db_5_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_mysql_args_nodb) sed "s/db_5_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_db_args_nodb)
} }
function sanity_check() { function sanity_check() {
trap "$(shopt -po errexit)" RETURN trap "$(shopt -po errexit)" RETURN
set +e set +e
echo -n "running sanity checks ..." echo -n "running sanity checks ..."
msg="$($MYSQL_CMD $(get_mysql_args) < "utils/sanity_check.sql" 2>/dev/null)" msg="$($MYSQL_CMD $(get_db_args) < "utils/sanity_check.sql" 2>/dev/null)"
code="$?" code="$?"
if [ "$code" -eq "0" ] ; then if [ "$code" -eq "0" ] ; then
echo " [OK]" echo " [OK]"
...@@ -150,7 +150,7 @@ function sanity_check() { ...@@ -150,7 +150,7 @@ function sanity_check() {
# 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_mysql_args) < "$SQL_FILE" $MYSQL_CMD $(get_db_args) < "$SQL_FILE"
cat <<EOF cat <<EOF
If this is not the same SQL server where the SQL dump was originally created If this is not the same SQL server where the SQL dump was originally created
from, make sure that a user with sufficient permissions exists. Note that you from, make sure that a user with sufficient permissions exists. Note that you
...@@ -159,7 +159,7 @@ EOF ...@@ -159,7 +159,7 @@ EOF
} }
function test-connection() { function test-connection() {
$MYSQL_CMD $(get_mysql_args_nodb) -e "select 0;" $MYSQL_CMD $(get_db_args_nodb) -e "select 0;"
} }
# Creates a user and grants it sufficient rights. # Creates a user and grants it sufficient rights.
...@@ -183,7 +183,7 @@ function grant() { ...@@ -183,7 +183,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_mysql_args_nodb) -s -N -e "$CMD") = 0 ]] || { [[ $($MYSQL_CMD $(get_db_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};\"'"
...@@ -197,7 +197,7 @@ function grant() { ...@@ -197,7 +197,7 @@ function grant() {
# FIXME Are all these permissions necessary? See # FIXME Are all these permissions necessary? See
# https://gitlab.indiscale.com/caosdb/src/caosdb-mysqlbackend/-/issues/28 "Default # https://gitlab.indiscale.com/caosdb/src/caosdb-mysqlbackend/-/issues/28 "Default
# installation target does not work for existing databases" # installation target does not work for existing databases"
$MYSQL_CMD $(get_mysql_args_nodb) <<EOF $MYSQL_CMD $(get_db_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';
...@@ -212,16 +212,16 @@ EOF ...@@ -212,16 +212,16 @@ EOF
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_mysql_args_nodb) -e "DROP USER '${DATABASE_USER}'@'${host}';" || true $MYSQL_CMD $(get_db_args_nodb) -e "DROP USER '${DATABASE_USER}'@'${host}';" || true
done done
"$MYSQLADMIN_CMD" $(get_mysql_args_nodb) -f drop "$DROPDB" "$MYSQLADMIN_CMD" $(get_db_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_mysql_args_nodb) -D "${1-${DATABASE_NAME}}" -e "show tables;" > /dev/null 2>&1 \ $MYSQL_CMD $(get_db_args_nodb) -D "${1-${DATABASE_NAME}}" -e "show tables;" > /dev/null 2>&1 \
&& return 0 || return 1 && return 0 || return 1
} }
...@@ -250,7 +250,7 @@ function grant-permission() { ...@@ -250,7 +250,7 @@ function grant-permission() {
fi fi
cmd="SELECT COUNT(1) from roles where name='${role}';" cmd="SELECT COUNT(1) from roles where name='${role}';"
count=$($MYSQL_CMD $(get_mysql_args) -AN -e "$cmd") count=$($MYSQL_CMD $(get_db_args) -AN -e "$cmd")
if [[ $count == "0" ]]; then if [[ $count == "0" ]]; then
echo "Role not found!" echo "Role not found!"
exit 1 exit 1
...@@ -259,7 +259,7 @@ function grant-permission() { ...@@ -259,7 +259,7 @@ function grant-permission() {
cmd="INSERT INTO permissions (role, permissions) VALUE ('${role}', '${permissions}')" cmd="INSERT INTO permissions (role, permissions) VALUE ('${role}', '${permissions}')"
cmd+="ON DUPLICATE KEY UPDATE role='${role}', permissions='${permissions}'" cmd+="ON DUPLICATE KEY UPDATE role='${role}', permissions='${permissions}'"
cmd+=";" cmd+=";"
$MYSQL_CMD $(get_mysql_args) -e "$cmd" $MYSQL_CMD $(get_db_args) -e "$cmd"
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment