Add scripts to save and restore baseline data

This commit is contained in:
Maikel Linke
2024-10-25 15:07:39 +11:00
parent decf1e6f03
commit 8a0d9d99e5
2 changed files with 41 additions and 0 deletions

View File

@@ -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."

View File

@@ -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."