Pushing to staging first loads staging baseline data

This commit is contained in:
Rohan Mitchell
2015-04-22 12:37:06 +10:00
parent 35536a629c
commit 7d4a4f8f9d
2 changed files with 31 additions and 0 deletions

View File

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

View File

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