Last active
August 29, 2015 14:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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