bus-detective/bus-detective

View on GitHub
bin/data

Summary

Maintainability
Test Coverage
#!/bin/bash

set -x

set -e

DATABASE='bus_detective_development'
HEROKU_APP='busdetective'

dropdb ${DATABASE} --if-exists
createdb ${DATABASE}

if [ -z $BACKUP_ID ]; then
    heroku pg:backups capture DATABASE_URL --app ${HEROKU_APP}
    DUMP_FILE="db/${HEROKU_APP}-latest.dump"
else
    DUMP_FILE="db/${HEROKU_APP}-${BACKUP_ID}.dump"
fi

BACKUP_ID=`heroku pg:backups --app ${HEROKU_APP} | grep -Ehom1 "^b\d{3}"`
BACKUP_URL=`heroku pg:backups public-url ${BACKUP_ID} --app ${HEROKU_APP} | grep -m1 -E "" | sed "s/'//g" | sed "s/ //g"`

if [ ! -f $DUMP_FILE ]; then
    curl -Lo $DUMP_FILE $BACKUP_URL
fi
pg_restore --verbose --no-acl --no-owner -d ${DATABASE} $DUMP_FILE