Skip to content

Instantly share code, notes, and snippets.

@AD7six
Last active August 29, 2015 14:16
Show Gist options
  • Save AD7six/0afcf0f206b13a877fab to your computer and use it in GitHub Desktop.
Save AD7six/0afcf0f206b13a877fab to your computer and use it in GitHub Desktop.
Run phinx migrations in a loop until they pass. This is useful if the phinx log is not in sync with the schema, which can happen through error or e.g. by taking a bare schema from one environment (without data) and importing it to another and then running migratiions.
#!/bin/bash
re="[0-9]{14}" # migration ids are the datetime as a 14 digit number - find them
env=${1-development}
db="app"
if [[ $env != 'development' ]]; then
db="app_test"
fi
phinx migrate -e $env
while [ $? -ne 0 ]; do
output=`phinx migrate -e $env 2>/dev/null`
if [[ $output =~ $re ]]; then
mysql -e "insert into ${db}.phinxlog values('${BASH_REMATCH[0]}', now(), now());"
echo ""
echo "Skipping migration ${BASH_REMATCH[0]} restarting migrate..."
echo ""
phinx migrate -e $env
else
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment