Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added script to apply all new evolutions #3427

Merged
merged 9 commits into from
Nov 22, 2018
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;