diff --git a/script/ci/restore-staging-baseline.sh b/script/ci/restore-staging-baseline.sh new file mode 100755 index 0000000000..c2945b86cf --- /dev/null +++ b/script/ci/restore-staging-baseline.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Restore baseline data for staging in case a pull request messed with +# the database. + +set -e + +: ${DB_USER='ofn_user'} +: ${DB_DATABASE='openfoodnetwork'} + +srcdir="$HOME/apps/openfoodnetwork/shared" +srcfile="$srcdir/staging-baseline.sql.gz" + +if [ -f "$srcfile" ]; then + echo "Restoring data from: $srcfile" +else + >&2 echo "[Error] No baseline data available at: $srcfile" + exit 1 +fi + +dropdb -h localhost -U "$DB_USER" "$DB_DATABASE" --if-exists +createdb -h localhost -U "$DB_USER" "$DB_DATABASE" + +gunzip -c "$srcfile" | psql -h localhost -U "$DB_USER" "$DB_DATABASE" +echo "Staging baseline data restored." diff --git a/script/ci/save-staging-baseline.sh b/script/ci/save-staging-baseline.sh new file mode 100755 index 0000000000..89225eb7fd --- /dev/null +++ b/script/ci/save-staging-baseline.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Save baseline data for staging which can be restored in case a pull request +# messes with the database. + +set -e + +: ${DB_USER='ofn_user'} +: ${DB_DATABASE='openfoodnetwork'} + +dstdir="$HOME/apps/openfoodnetwork/shared" +dstfile="$dstdir/staging-baseline.sql.gz" + +mkdir -p "$dstdir" +pg_dump -h localhost -U "$DB_USER" "$DB_DATABASE" | gzip > "$dstfile" +echo "Staging baseline data saved."