Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #!/bin/bash
  2. # This file is managed by vagrant, do not modify manually
  3. # To override, on the host copy default/files/usr/local/bin/migrateDb
  4. # to local/files/usr/local/bin/migrateDb
  5. # and reprovision
  6.  
  7. DATABASE_URL=${DATABASE_URL:-mysql://user:pass@host/db}
  8. if [[ "$DATABASE_URL" =~ ^([^:]+)://([^:]+):([^@]*)@([^/]+)/(.*)$ ]]; then
  9. DATABASE_SCHEME=${BASH_REMATCH[1]}
  10. DATABASE_USER=${BASH_REMATCH[2]}
  11. DATABASE_PASS=${BASH_REMATCH[3]}
  12. DATABASE_HOST=${BASH_REMATCH[4]}
  13. DATABASE_DB=${BASH_REMATCH[5]}
  14. fi
  15.  
  16. ## Errors that don't matter when re running a migration
  17. ACCEPTABLE_MIGRATION_RESULT_RE="^$|already exists|Duplicate column|Duplicate key|Can't DROP"
  18.  
  19. echo "Ensuring migrations are current"
  20. echo ""
  21. if [[ ! -d /tmp/migrations ]]; then
  22. git clone <migrations repo source> /tmp/migrations
  23. else
  24. (cd /tmp/migrations; git pull > /dev/null)
  25. fi
  26.  
  27. echo "Running migrations"
  28. echo ""
  29. migrations=`find /tmp/migrations -type f | sort`
  30. for migration in $migrations; do
  31. echo " Running ${migration##*/}"
  32. output=`mysql --user=$DATABASE_USER --password=$DATABASE_PASS --host=$DATABASE_HOST $DATABASE_DB < $migration 2>&1`
  33. if ! [[ "$output" =~ $ACCEPTABLE_MIGRATION_RESULT_RE ]]; then
  34. echo " $output"
  35. fi
  36. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement