diff --git a/script/load_staging_baseline.sh b/script/load_staging_baseline.sh new file mode 100644 index 0000000000..0a59b66d3b --- /dev/null +++ b/script/load_staging_baseline.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Every time staging is deployed, we load a baseline data set before running the new code's +# migrations. This script loads the baseline data set, after first taking a backup of the +# current database. + +set -e + +cd /home/openfoodweb/apps/openfoodweb/current + +echo "Stopping unicorn..." +service unicorn_openfoodweb stop + +echo "Backing up current data..." +mkdir -p db/backup +pg_dump -h localhost -U openfoodweb openfoodweb_production |gzip > db/backup/staging-`date +%Y%m%d%H%M%S`.sql.gz + +echo "Loading baseline data..." +dropdb -U openfoodweb -w openfoodweb_production +createdb -U openfoodweb -w openfoodweb_production +gunzip -c db/backup/staging-baseline.sql.gz |psql -h localhost -U openfoodweb openfoodweb_production + +echo "Restarting unicorn..." +service unicorn_openfoodweb start + +echo "Done!" diff --git a/script/push_to_staging.sh b/script/push_to_staging.sh index e3a16ebb3b..c2c176bb2a 100755 --- a/script/push_to_staging.sh +++ b/script/push_to_staging.sh @@ -2,9 +2,14 @@ set -e +# Add staging git remote if required ST2_TEST=`git remote | grep -s 'staging2' || true` if [[ "$ST2_TEST" != *staging2* ]]; then git remote add staging2 openfoodweb@ofn-staging2:apps/openfoodweb/current fi +echo "--- Loading baseline data" +ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/load_staging_baseline.sh" + +echo "--- Pushing to staging" [[ $(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]]