Created
November 9, 2018 09:27
-
-
Save hossainemruz/522fbcc69bee4f73fe63a3bcbff336c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
DB_NAME="database_name" | |
DB_USER="username" | |
DB_PASS="password" | |
DB_HOST="localhost" | |
DB_PORT="3306" | |
while ! nc -q 1 $DB_HOST $DB_PORT </dev/null; do | |
echo "Waiting for database to be ready....." | |
sleep 5 | |
done | |
#get current version | |
GET_DATABASE_VERSION="SELECT name FROM version TOP 1" | |
# | |
echo "Getting data version" | |
version=$(mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME -e "SELECT name FROM version") | |
#trim string to get current version name | |
version=${version:5} | |
x="./config/scripts/migration/$version" | |
echo $version | |
MIGRATION_PATH="./config/scripts/migration/*" | |
#get migration file for newer version | |
for filename in $MIGRATION_PATH -maxdepth 2 | |
do | |
if [[ -f $filename ]]; then | |
if [[ "$filename" > "$x" ]] || [ "$filename" == "$x" ]; then | |
echo "Running migration file: $filename" | |
mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME < $filename | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment