diff --git a/script/ci/includes.sh b/script/ci/includes.sh index 4b07dacfdc..ee59a732d7 100644 --- a/script/ci/includes.sh +++ b/script/ci/includes.sh @@ -11,3 +11,17 @@ function exit_unless_master_merged { exit 1 fi } + +function drop_and_recreate_database { + # Adapted from: http://stackoverflow.com/questions/12924466/capistrano-with-postgresql-error-database-is-being-accessed-by-other-users + psql -U openfoodweb postgres < pg_backend_pid() +AND datname='$1'; +DROP DATABASE $1; +CREATE DATABASE $1; +EOF +} diff --git a/script/ci/load_staging_baseline.sh b/script/ci/load_staging_baseline.sh index 0a59b66d3b..c5408b1328 100755 --- a/script/ci/load_staging_baseline.sh +++ b/script/ci/load_staging_baseline.sh @@ -5,6 +5,7 @@ # current database. set -e +source ./script/ci/includes.sh cd /home/openfoodweb/apps/openfoodweb/current @@ -16,8 +17,7 @@ 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 +drop_and_recreate_database "openfoodweb_production" gunzip -c db/backup/staging-baseline.sql.gz |psql -h localhost -U openfoodweb openfoodweb_production echo "Restarting unicorn..."