Skip to content

Commit

Permalink
Added script to apply all new evolutions (#3427)
Browse files Browse the repository at this point in the history
* added script to apply all new evolutions

* added script

* use scriptdir and use relative paths from there

* fix spelling mistake

* Refactor the script for readability
  • Loading branch information
rschwanhold authored Nov 22, 2018
1 parent fcb0792 commit 07b13ed
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
"enable-autologin": "sed -i -e 's/enableDevAutoLogin = false/enableDevAutoLogin = true/g' ./conf/application.conf",
"disable-autologin": "sed -i -e 's/enableDevAutoLogin = true/enableDevAutoLogin = false/g' ./conf/application.conf",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"postcheckout": "echo 'Deleting auto-generated flow files...' && rm -f app/assets/javascripts/test/snapshots/flow-check/*.js"
"postcheckout": "echo 'Deleting auto-generated flow files...' && rm -f app/assets/javascripts/test/snapshots/flow-check/*.js",
"apply-evolutions": "tools/postgres/apply_evolutions.sh"
},
"lint-staged": {
"*.js": [
Expand Down
35 changes: 35 additions & 0 deletions tools/postgres/apply_evolutions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -Eeuo pipefail

scriptdir="$(dirname "$0")"

# find schema version
schema_version=`psql -A -U postgres -h localhost --dbname="webknossos" -t -c "SELECT * FROM webknossos.releaseinformation"`
echo "Schema version: ${schema_version}"

# assert that the found schema version is a number
re='^[0-9]+$'
if ! [[ $schema_version =~ $re ]] ; then
echo "Error: Schema version is not a number" >&2; exit 1
fi

# get list of evolutions to apply
files=""
for entry in "${scriptdir}/../../conf/evolutions"/*.sql
do
tmp_number=`grep -oP "[0-9]{3}" <<< $entry`
evolution_number=$((10#$tmp_number)) # force the number to be decimal
if (( evolution_number > schema_version )); then
files="$files -f $entry"
fi;
done
# apply evolutions
if [ -n "$files" ]; then
echo "Applying following evolutions: $files"
`PGPASSWORD=postgres psql -U postgres -h localhost --dbname="webknossos" -v ON_ERROR_STOP=ON -q $files`
echo "Successfully applied the evolutions after $schema_version"
else
echo "There are no evolutions that can be applied."
fi;

0 comments on commit 07b13ed

Please sign in to comment.