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
4ea8cd91
Verified
Commit
4ea8cd91
authored
2 months ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: Renamed function "check_version", added documentation.
parent
14649e1d
No related branches found
No related tags found
1 merge request
!33
Fix accent sensitivity
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils/patch_header.sh
+52
-13
52 additions, 13 deletions
utils/patch_header.sh
with
52 additions
and
13 deletions
utils/patch_header.sh
+
52
−
13
View file @
4ea8cd91
#
# ** header v3.0
# This file is a part of the CaosDB Project.
# This file is a part of the LinkAhead Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2019, 2020 Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2019, 2020
, 2025
Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2020 Henrik tom Wörden <h.tomwoerden@indiscale.com>
# Copyright (C) 2020 IndiScale <info@indiscale.com>
# Copyright (C) 2020
, 2025
IndiScale <info@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
...
...
@@ -21,12 +19,20 @@
# 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/>.
#
# ** end header
#
###############################################################################
# header for patch scripts #
###############################################################################
#
# This file defines the following functions (see below for more detailed descriptions):
#
# - check_version_or_exit: Check if the stored version is as expected.
# - update_version: Set the stored version.
# - dump_table: Store table content into a file.
# - redo_table: Apply the table content stored by dump_table.
#
# This file also sets the `errexit` option (`set -e`).
#
set
-e
...
...
@@ -63,7 +69,7 @@ configuration make file. Notable examples are:
- DATABASE_USER_PW
EOF
)
)
function
_print_help
()
{
echo
-e
"
$USAGE
"
...
...
@@ -115,21 +121,51 @@ done
if
[
-n
"
$PATCH
"
]
;
then
echo
-ne
"applying patch
$PATCH
to
$DATABASE_NAME
... "
fi
# @param $1: db version string, e.g. v2.0.0
# @return: 0 on success, 1 on failure
function
check_version
{
# usage: check_version_or_exit version
#
# Check if the version string is as expected. Otherwise, `exit 0`.
#
# Arguments
# ---------
#
# version: str
# The expected database version string, e.g. 'v2.0.0'
#
# Returns
# -------
#
# 0 on success
function
check_version_or_exit
{
local
version
=
$(
$MYSQL_CMD
$(
get_db_args
)
-B
-e
"Select CaosDBVersion();"
)
if
[[
"
$(
echo
$version
|
sed
's/^CaosDBVersion()\s//'
)
"
=
"
$1
"
]]
;
then
local
version
=
"
$(
echo
$version
|
sed
's/^CaosDBVersion()\s//'
)
"
if
[[
"
$version
"
=
"
$1
"
]]
;
then
return
0
fi
uptodate
}
# @param $1: new version string
# Deprecated name, call "check_version_or_exit" directly instead.
function
check_version
{
check_version_or_exit
"
$1
"
}
# usage: update_version version
#
# Set the version string.
#
# Arguments
# ---------
#
# version: str
# The new database version string, e.g. 'v2.0.0'
function
update_version
{
mysql_execute
"DROP FUNCTION IF EXISTS CaosDBVersion; CREATE FUNCTION CaosDBVersion() RETURNS VARCHAR(255) DETERMINISTIC RETURN '
$1
';"
}
# usage: dump_table table
#
# Dump the table given in the argument into file "caosdb.<table>.<OLD_VERSION>.dump.sql"
function
dump_table
{
if
[[
-z
$MYSQLDUMP_CMD
]]
;
then
echo
"Cannot find mysqldump program!"
>
&2
...
...
@@ -139,6 +175,9 @@ function dump_table {
>
${
DATABASE_NAME
}
.
${
1
}
.
${
OLD_VERSION
}
.dump.sql
}
# usage: redo_table table
#
# Apply the dump from `dump_table` to the database. Takes the same argument.
function
redo_table
{
$MYSQL_CMD
$(
get_db_args
)
<
${
DATABASE_NAME
}
.
${
1
}
.
${
OLD_VERSION
}
.dump.sql
}
...
...
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