Skip to content
Snippets Groups Projects
Commit 7495c0c1 authored by Sina Rohde's avatar Sina Rohde
Browse files

Merge remote-tracking branch 'origin/release-v7.0.2' into f-overview

parents fbc10596 bd2fa346
No related branches found
No related tags found
1 merge request!28F overview
Pipeline #44830 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
...@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file. ...@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ##
### Added ###
### Changed ###
### Deprecated ###
### Removed ###
### 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 ###
## [7.0.1] - 2023-11-01 ## [7.0.1] - 2023-11-01
(Timm Fitschen) (Timm Fitschen)
...@@ -87,8 +108,6 @@ This is a major update. Switching from integer ids for internal and external use ...@@ -87,8 +108,6 @@ This is a major update. Switching from integer ids for internal and external use
* Change signature of procedure `retrieveEntityProperties` - `EntityID VARCHAR(255)`, `DomainID VARCHAR(255)` * Change signature of procedure `retrieveEntityProperties` - `EntityID VARCHAR(255)`, `DomainID VARCHAR(255)`
* Change signature of procedure `updateEntity` - `EntityID VARCHAR(255)` * Change signature of procedure `updateEntity` - `EntityID VARCHAR(255)`
### Deprecated ###
### Removed ### ### Removed ###
* Deactivate procedure `delete_all_entity_versions`. This might be used in the * Deactivate procedure `delete_all_entity_versions`. This might be used in the
...@@ -107,18 +126,12 @@ This is a major update. Switching from integer ids for internal and external use ...@@ -107,18 +126,12 @@ This is a major update. Switching from integer ids for internal and external use
* Change signature of procedure `getFileIdByPath` - `FilePath TEXT` - this length is needed for the path column of `file_entities`. * Change signature of procedure `getFileIdByPath` - `FilePath TEXT` - this length is needed for the path column of `file_entities`.
### Security ###
## [5.0.0] - 2021-10-28 ## ## [5.0.0] - 2021-10-28 ##
### Added ### ### Added ###
* #33 CI pipeline for MySQL (was only MariaDB before). * #33 CI pipeline for MySQL (was only MariaDB before).
### Changed ###
### Deprecated ###
### Removed ### ### Removed ###
* `getRules` procedure and the `rules` table. The jobs rules are being * `getRules` procedure and the `rules` table. The jobs rules are being
...@@ -131,8 +144,6 @@ This is a major update. Switching from integer ids for internal and external use ...@@ -131,8 +144,6 @@ This is a major update. Switching from integer ids for internal and external use
* #32 Removed unused `groups` table from installation routines which prevented * #32 Removed unused `groups` table from installation routines which prevented
the installation with MySQL 8. the installation with MySQL 8.
### Security ###
## [4.1.0] - 2021-06-11 ## ## [4.1.0] - 2021-06-11 ##
### Added ### ### Added ###
...@@ -170,8 +181,6 @@ This is a major update. Switching from integer ids for internal and external use ...@@ -170,8 +181,6 @@ This is a major update. Switching from integer ids for internal and external use
* `createTmpTable` * `createTmpTable`
* Added a `direct` column to `archive_isa` table * Added a `direct` column to `archive_isa` table
### Deprecated ###
### Removed ### ### Removed ###
* unused procedures: * unused procedures:
...@@ -197,8 +206,6 @@ This is a major update. Switching from integer ids for internal and external use ...@@ -197,8 +206,6 @@ This is a major update. Switching from integer ids for internal and external use
version resultet in an error. See corresponding test in `caosdb-pyinttest` version resultet in an error. See corresponding test in `caosdb-pyinttest`
`tests/test_versioning.py::test_datatype_without_name` `tests/test_versioning.py::test_datatype_without_name`
### Security ###
## [3.0.0] - 2020-09-01 ## ## [3.0.0] - 2020-09-01 ##
### Added ### ### Added ###
...@@ -252,5 +259,3 @@ This is a major update. Switching from integer ids for internal and external use ...@@ -252,5 +259,3 @@ This is a major update. Switching from integer ids for internal and external use
* Bug in `updateEntity.sql` (when updating the primary name without a prior call * Bug in `updateEntity.sql` (when updating the primary name without a prior call
to `deleteEntityProperties`). Same thing for `deleteEntity`. to `deleteEntityProperties`). Same thing for `deleteEntity`.
* #21 Bug which prevented deletion of deeply inheriting entities, if versioning was enabled. * #21 Bug which prevented deletion of deeply inheriting entities, if versioning was enabled.
### Security ###
...@@ -86,6 +86,7 @@ pipeline-test: ...@@ -86,6 +86,7 @@ pipeline-test:
echo 'DATABASE_USER_HOST_LIST="%,"' >> .config echo 'DATABASE_USER_HOST_LIST="%,"' >> .config
echo "MYSQL_USER_PASSWORD=$(MYSQL_ROOT_PASSWORD)" >> .config echo "MYSQL_USER_PASSWORD=$(MYSQL_ROOT_PASSWORD)" >> .config
echo "MYSQL_HOST=$(SQL_HOST)" >> .config echo "MYSQL_HOST=$(SQL_HOST)" >> .config
echo "MYSQL_OPTS=--protocol=TCP" >> .config
sleep 10 sleep 10
make install make install
./utils/make_db restore_db tests/example.dump.sql ./utils/make_db restore_db tests/example.dump.sql
......
...@@ -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
...@@ -34,30 +34,31 @@ DELIMITER // ...@@ -34,30 +34,31 @@ DELIMITER //
* ---------- * ----------
* *
* versioned : boolean * versioned : boolean
* If True, sourceSet and targetSet have an _iversion column, otherwise that column will be * If True, sourceSet and targetSet have an _iversion column, otherwise that column will be ignored
* ignored (or only HEAD will be inserted into targetSet). * (or only HEAD will be inserted into targetSet).
*/ */
CREATE PROCEDURE db_5_0.applyPOV(in sourceSet VARCHAR(255), /* (?) Name of the table that the POV will be applied to. This can be a temporary table. */ CREATE PROCEDURE db_5_0.applyPOV(in sourceSet VARCHAR(255), /* Name of the table that the POV will be applied to. This can be a temporary table or the `entities` table */
in targetSet VARCHAR(255), /* (?) Name of the result table of this POV. */ in targetSet VARCHAR(255), /* Name of the result table of this POV. After the filter has been applied this table only contains matching
entity ids. This may be NULL or same as sourceSet. In that case the filter is applied in-place (delete non-matching). Otherwise the filter is applied by copying only the matching ids from the *source* set to the *target* set. */
in propertiesTable VARCHAR(255), in propertiesTable VARCHAR(255),
in refIdsTable VARCHAR(255), in refIdsTable VARCHAR(255), /* Name of a tmp table that contains all ids of children of the value interpreted as entity name or id */
in o CHAR(4), /* The operator for this operation. can be one of: in o CHAR(4), /* The operator for this operation. can be one of:
0 check for "equals NULL" 0 check for "equals NULL"
!0 check for "not NULL" !0 check for "not NULL"
-> check whether a reference exists -> check whether a reference exists
( (?) check for datetime intervals ( check for datetime interval (say "in")
!( (?) check for being outside of datetime intervals !( check for being outside of datetime intervals (say "not in")
other operators (all SQL operators (?)) other operators (all valid SQL operators)
these other operators can be used either with or without an aggregation these other operators can be used either with or without an aggregation
to use an aggregation set agg to non-zero to use an aggregation set agg to non-zero
all SQL aggregations can be used all SQL aggregations can be used
*/ */
in vText VARCHAR(255), /* (?) the text value to be checked against using operator o */ in vText VARCHAR(255), /* the text value to be checked against using operator o */
in vInt INT, /* the integer value to be checked against using operator o */ in vInt INT, /* the integer value to be checked against using operator o */
in vDouble DOUBLE, /* the double value to be checked against using operator o */ in vDouble DOUBLE, /* the double value to be checked against using operator o */
in unit_sig BIGINT, in unit_sig BIGINT, /* signatur of the unit given by the user. used when we need to convert units. */
in vDoubleStdUnit DOUBLE, /* The numeric value, converted according to the unit rules. */ in vDoubleStdUnit DOUBLE, /* The numeric value, converted according to the unit rules. */
in stdUnit_sig BIGINT, in stdUnit_sig BIGINT, /* signatur of the normalized/standardized unit, e.g when unit_sig is "km/h" this might be "m/s". */
in vDateTime VARCHAR(255), in vDateTime VARCHAR(255),
in vDateTimeDotNotation VARCHAR(255), in vDateTimeDotNotation VARCHAR(255),
in agg CHAR(3), /* an SQL aggregate function or NULL when no aggregation should be used */ in agg CHAR(3), /* an SQL aggregate function or NULL when no aggregation should be used */
...@@ -81,6 +82,10 @@ POV_LABEL: BEGIN ...@@ -81,6 +82,10 @@ POV_LABEL: BEGIN
DECLARE keepTabl VARCHAR(255) DEFAULT NULL; DECLARE keepTabl VARCHAR(255) DEFAULT NULL;
DECLARE existence_op VARCHAR(255) DEFAULT "EXISTS"; DECLARE existence_op VARCHAR(255) DEFAULT "EXISTS";
#-- ######### HINT ##############
#-- first the appropriate statement is created which in the end prepared and executed
#-- #############################
IF o = '->' THEN IF o = '->' THEN
#-- special case: pure reference property #-- special case: pure reference property
call applyRefPOV(sourceSet,targetSet, propertiesTable, refIdsTable, versioned); call applyRefPOV(sourceSet,targetSet, propertiesTable, refIdsTable, versioned);
...@@ -229,6 +234,8 @@ POV_LABEL: BEGIN ...@@ -229,6 +234,8 @@ POV_LABEL: BEGIN
IF o = "!=" AND refIdsTable IS NOT NULL THEN IF o = "!=" AND refIdsTable IS NOT NULL THEN
SET existence_op = "NOT EXISTS"; SET existence_op = "NOT EXISTS";
END IF; END IF;
/* select all entities that reference the entity or a child of the
* value interpreted as ID*/
SET sRefData = IF(vText IS NULL, SET sRefData = IF(vText IS NULL,
' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `reference_data`', ' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `reference_data`',
IF(refIdsTable IS NULL, IF(refIdsTable IS NULL,
...@@ -243,6 +250,7 @@ POV_LABEL: BEGIN ...@@ -243,6 +250,7 @@ POV_LABEL: BEGIN
END IF; END IF;
#-- create array of statement parts (and replace null with empty string) (?)
SET data = CONCAT('(',sTextData, SET data = CONCAT('(',sTextData,
IF(sNameData IS NULL, '', sNameData), IF(sNameData IS NULL, '', sNameData),
IF(sEnumData IS NULL, '', sEnumData), IF(sEnumData IS NULL, '', sEnumData),
...@@ -259,6 +267,7 @@ POV_LABEL: BEGIN ...@@ -259,6 +267,7 @@ POV_LABEL: BEGIN
call createTmpTable(keepTabl, versioned); call createTmpTable(keepTabl, versioned);
IF versioned THEN IF versioned THEN
#-- generate statement from statement parts #-- generate statement from statement parts
#-- (versioned section)
SET @stmtPOVkeepTblStr = CONCAT( SET @stmtPOVkeepTblStr = CONCAT(
'INSERT IGNORE INTO `', keepTabl, '` (id, _iversion) SELECT entity_id AS id, _iversion FROM ', data, 'INSERT IGNORE INTO `', keepTabl, '` (id, _iversion) SELECT entity_id AS id, _iversion FROM ', data,
' as data', IF(propertiesTable IS NULL, '', CONCAT( ' as data', IF(propertiesTable IS NULL, '', CONCAT(
...@@ -299,7 +308,14 @@ POV_LABEL: BEGIN ...@@ -299,7 +308,14 @@ POV_LABEL: BEGIN
DEALLOCATE PREPARE stmtPOVkeepTbl; DEALLOCATE PREPARE stmtPOVkeepTbl;
ELSE ELSE
#-- generate statement from statement parts #-- generate statement from statement parts
SET @stmtPOVkeepTblStr = CONCAT('INSERT IGNORE INTO `', keepTabl, '` (id) SELECT DISTINCT entity_id AS id FROM ', data, ' as data', IF(propertiesTable IS NULL, '', CONCAT(' WHERE EXISTS (Select 1 from `', propertiesTable, '` AS prop WHERE prop.id = data.property_id AND (prop.id2=data.entity_id OR prop.id2=0))'))); SET @stmtPOVkeepTblStr = CONCAT(
'INSERT IGNORE INTO `', keepTabl,
'` (id) SELECT DISTINCT entity_id AS id FROM ', data, ' as data',
IF(propertiesTable IS NULL, '',
CONCAT(' WHERE EXISTS (Select 1 from `', propertiesTable,
'` AS prop WHERE prop.id = data.property_id AND
(prop.id2=data.entity_id OR prop.id2=0))')));
#-- (unversioned section)
SET @stmtPOVStr = CONCAT( SET @stmtPOVStr = CONCAT(
IF(targetSet IS NULL, IF(targetSet IS NULL,
......
...@@ -60,7 +60,14 @@ BEGIN ...@@ -60,7 +60,14 @@ BEGIN
SELECT conv( concat( substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)),16,10) div 10000 - (141427 * 24 * 60 * 60 * 1000) as current_mills INTO t1 from (select uuid() uid) as alias; SELECT conv( concat( substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)),16,10) div 10000 - (141427 * 24 * 60 * 60 * 1000) as current_mills INTO t1 from (select uuid() uid) as alias;
call createTmpTable2(propertiesTable); call createTmpTable2(propertiesTable);
-- fill in all properties named "PropertyName" -- Fill in all properties (plus the domain id and entity id) named
-- "PropertyName", be it their default name or their overridden name.
-- We need *all* properties (mind, the properties of entities not
-- abstract properties) with the given name. If an abstract
-- property has the name "person" it might have the name "author" in
-- the "Article" record type. Now, if I want to collect all properties
-- of the Article named "author" I need to look into the name_overrides
-- table.
SET @initPOVPropertiesTableStmt1 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) SELECT property_id, entity_id, domain_id from name_overrides WHERE name = ? UNION ALL SELECT entity_id, domain_id, 0 FROM name_data WHERE value = ?;'); SET @initPOVPropertiesTableStmt1 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) SELECT property_id, entity_id, domain_id from name_overrides WHERE name = ? UNION ALL SELECT entity_id, domain_id, 0 FROM name_data WHERE value = ?;');
PREPARE stmt FROM @initPOVPropertiesTableStmt1; PREPARE stmt FROM @initPOVPropertiesTableStmt1;
SET @PropertyName = PropertyName; SET @PropertyName = PropertyName;
......
...@@ -24,10 +24,11 @@ ...@@ -24,10 +24,11 @@
DROP PROCEDURE IF EXISTS db_5_0.initSubEntity; DROP PROCEDURE IF EXISTS db_5_0.initSubEntity;
DELIMITER // DELIMITER //
/* /*
* Initialize a new temporary table by loading an entity and all of its children * Initialize a new temporary table by loading an entity (by name or by id or
* into the table (i.e. their internal ids). * both) and all of its children into the table (i.e. their internal ids).
*
* The table name has to be provided.
* *
* This is used by initPOVRefidsTable and initBackReference for sub-property filtering. * This is used by initPOVRefidsTable and initBackReference for sub-property filtering.
* *
...@@ -45,6 +46,7 @@ BEGIN ...@@ -45,6 +46,7 @@ BEGIN
DECLARE ecount INT DEFAULT 0; DECLARE ecount INT DEFAULT 0;
DECLARE op VARCHAR(255) DEFAULT '='; DECLARE op VARCHAR(255) DEFAULT '=';
IF LOCATE("%", ename) > 0 THEN IF LOCATE("%", ename) > 0 THEN
SET op = "LIKE"; SET op = "LIKE";
END IF; END IF;
......
...@@ -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 "$MYSQL_USER" ]; then
mysql_con_arguments="--user=$DATABASE_USER" mysql_con_arguments="--user=$MYSQL_USER"
fi fi
if [ "$DATABASE_USER_PW" ]; then if [ -n "$MYSQL_USER_PASSWORD" ]; then
mysql_con_arguments="$mysql_con_arguments --password=$DATABASE_USER_PW" mysql_con_arguments="$mysql_con_arguments --password=$MYSQL_USER_PASSWORD"
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.
Please register or to comment