Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-mysqlbackend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-mysqlbackend
Commits
caef918c
Commit
caef918c
authored
5 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: trying to get it work
parent
e50e2182
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
make_db
+14
-16
14 additions, 16 deletions
make_db
utils/helpers.sh
+40
-12
40 additions, 12 deletions
utils/helpers.sh
utils/patch_header.sh
+1
-2
1 addition, 2 deletions
utils/patch_header.sh
with
55 additions
and
30 deletions
make_db
+
14
−
16
View file @
caef918c
...
...
@@ -32,7 +32,6 @@ fi
source
$UTILSPATH
/load_settings.sh
source
$UTILSPATH
/helpers.sh
echo
"no1
$MYSQL_HOST
"
INSTALL_SQL_FILE
=
"db_2_0.sql"
set
-e
...
...
@@ -63,7 +62,7 @@ function _execute_tests () {
for
tfile
in
$TESTS
;
do
echo
"Running
$tfile
"
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
;
popd
...
...
@@ -84,9 +83,9 @@ function _install_unit_test_database () {
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
# cr
e
ate test user
grant
# update to latest
...
...
@@ -108,7 +107,7 @@ function _setup_mytap() {
pushd
libs
>
/dev/null
unzip
-u
mytap
*
.zip
>
/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
rm
-r
mytap
*
/
popd
>
/dev/null
...
...
@@ -143,18 +142,17 @@ Call 'make drop-$DATABASE_NAME' to delete that database or reconfigure with
exit
0
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
function
restore_db
()
{
SQL_FILE
=
"
$1
"
$MYSQL_CMD
$(
get_
con
_args
)
<
"
$SQL_FILE
"
$MYSQL_CMD
$(
get_
mysql
_args
)
<
"
$SQL_FILE
"
}
function
test-connection
()
{
echo
$SQL
$MYSQL_CMD
$(
get_con_args_nodb
)
-e
"select 0;"
$MYSQL_CMD
$(
get_mysql_args_nodb
)
-e
"select 0;"
}
# Creates a user and grants it sufficient rights.
...
...
@@ -178,7 +176,7 @@ function grant() {
if
[[
"
$1
"
==
"--strict"
]]
;
then
for
host
in
${
DATABASE_USER_HOST_LIST
//,/
}
;
do
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
"Please use another user or delete it, e.g. with"
echo
"'mysql -u
${
MYSQL_USER
}
-p -e
\"
DROP USER
${
DATABASE_USER
}
@
${
host
}
;
\"
'"
...
...
@@ -189,7 +187,7 @@ function grant() {
for
host
in
${
DATABASE_USER_HOST_LIST
//,/
}
;
do
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
'
$DATABASE_USER
'@'
$host
' identified by '
$DATABASE_USER_PW
';
GRANT USAGE ON *.* TO '
$DATABASE_USER
'@'
$host
';
...
...
@@ -203,17 +201,17 @@ EOF
# The first argument to this function is the database that shal be dropped.
function
drop
()
{
DROPDB
=
"
$1
"
for
host
in
${
DATABASE_USER_HOST_LIST
//,/
}
;
do
$MYSQL_CMD
$(
get_
con
_args_nodb
)
-e
"DROP USER '
${
DATABASE_USER
}
'@'
${
host
}
';"
||
true
done
"
$MYSQLADMIN_CMD
"
$(
get_
con
_args_nodb
)
-f
drop
"
$DROPDB
"
#
for host in ${DATABASE_USER_HOST_LIST//,/ } ; do
#
$MYSQL_CMD $(get_
mysql
_args_nodb) -e "DROP USER '${DATABASE_USER}'@'${host}';" || true
#
done
"
$MYSQLADMIN_CMD
"
$(
get_
mysql
_args_nodb
)
-f
drop
"
$DROPDB
"
}
# Returns 0 or non-zero, depending on whether the database exists already.
# Optional parameter: [DATABASE_NAME], else $DATABASE_NAME is used.
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
}
...
...
This diff is collapsed.
Click to expand it.
utils/helpers.sh
+
40
−
12
View file @
caef918c
...
...
@@ -19,14 +19,14 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
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
}
function
mysql_execute
{
#TODO is it meaningful that here always the database user is used???
set
+e
echo
$MYSQL_CMD
$(
get_con_args
)
-e
"
$1
"
$MYSQL_CMD
$(
get_con_args
)
-e
"
$1
"
$MYSQL_CMD
$(
get_db_args
)
-e
"
$1
"
ret
=
${
PIPESTATUS
[0]
}
if
[
"
$ret
"
-ne
0
]
;
then
failure
"MYSQL ERROR"
...
...
@@ -34,20 +34,47 @@ function mysql_execute {
set
-e
}
function
get_con_args
{
echo
"
$(
get_con_args_nodb
)
--database=
$DATABASE_NAME
"
function
get_mysql_args
{
# 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 [ "$DATABASE_NAME" = "caosdb" ];then
# echo "WRONGDB"
# exit 1
# fi
echo
"
$(
get_db_args_nodb
)
--database=
$DATABASE_NAME
"
}
function
get_db_args_nodb
{
if
[
"
$DATABASE_USER
"
]
;
then
mysql_con_arguments
=
"--user=
$DATABASE_USER
"
fi
if
[
"
$DATABASE_USER_PW
"
]
;
then
mysql_con_arguments
=
"
$mysql_con_arguments
--password=
$DATABASE_USER_PW
"
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
echo
$mysql_con_arguments
}
function
get_mysql_args_nodb
{
if
[
"
$LOGIN_PATH
"
]
;
then
mysql_con_arguments
=
"--login-path=
$LOGIN_PATH
"
mysql_con_arguments
=
"
$mysql_con_arguments
"
else
if
[
"
$
DATABASE
_USER
"
]
;
then
mysql_con_arguments
=
"--user=
$
DATABASE
_USER
"
if
[
"
$
MYSQL
_USER
"
]
;
then
mysql_con_arguments
=
"--user=
$
MYSQL
_USER
"
fi
if
[
"
$
DATABASE_USER_PW
"
]
;
then
mysql_con_arguments
=
"
$mysql_con_arguments
--password=
$
DATABASE_USER_PW
"
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
"
...
...
@@ -58,8 +85,9 @@ function get_con_args_nodb {
fi
echo
$mysql_con_arguments
}
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
{
...
...
This diff is collapsed.
Click to expand it.
utils/patch_header.sh
+
1
−
2
View file @
caef918c
...
...
@@ -25,7 +25,6 @@
# load useful functions #######################################################
.
$UTILSPATH
/helpers.sh
echo
$(
get_con_args
)
USAGE
=
"
$1
[ --env=ENV_FILE ] [ --patch=PATCH ] [ --backupdir=BACKUPDIR ]
\n\n
"
CMD_OPTIONS
=
$(
cat
<<
EOF
...
...
@@ -111,7 +110,7 @@ fi
# @param $1: db version string, e.g. v2.0.0
# @return: 0 on success, 1 on failure
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
return
0
fi
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment