Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This file is managed by vagrant, do not modify manually
- # To override, on the host copy default/files/usr/local/bin/migrateDb
- # to local/files/usr/local/bin/migrateDb
- # and reprovision
- DATABASE_URL=${DATABASE_URL:-mysql://user:pass@host/db}
- if [[ "$DATABASE_URL" =~ ^([^:]+)://([^:]+):([^@]*)@([^/]+)/(.*)$ ]]; then
- DATABASE_SCHEME=${BASH_REMATCH[1]}
- DATABASE_USER=${BASH_REMATCH[2]}
- DATABASE_PASS=${BASH_REMATCH[3]}
- DATABASE_HOST=${BASH_REMATCH[4]}
- DATABASE_DB=${BASH_REMATCH[5]}
- fi
- ## Errors that don't matter when re running a migration
- ACCEPTABLE_MIGRATION_RESULT_RE="^$|already exists|Duplicate column|Duplicate key|Can't DROP"
- echo "Ensuring migrations are current"
- echo ""
- if [[ ! -d /tmp/migrations ]]; then
- git clone <migrations repo source> /tmp/migrations
- else
- (cd /tmp/migrations; git pull > /dev/null)
- fi
- echo "Running migrations"
- echo ""
- migrations=`find /tmp/migrations -type f | sort`
- for migration in $migrations; do
- echo " Running ${migration##*/}"
- output=`mysql --user=$DATABASE_USER --password=$DATABASE_PASS --host=$DATABASE_HOST $DATABASE_DB < $migration 2>&1`
- if ! [[ "$output" =~ $ACCEPTABLE_MIGRATION_RESULT_RE ]]; then
- echo " $output"
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement