Last active
August 29, 2015 14:16
-
-
Save dovys/e38adbd27aa8d28cf66c to your computer and use it in GitHub Desktop.
Undo Groups migrations
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 | |
if [ -z "$1" ]; then echo "Usage: $0 database"; exit 0; fi | |
schema_dir='/code/in/schema/' | |
migrations=$(find $schema_dir -name '*-GROUPS*.sql') | |
for migration in $migrations; do | |
echo "UNDOING" $migration | |
sql=$(sed -n '/@UNDO/ { s///; :a; n; p; ba; }' $migration) | |
migrationId=$(echo $migration | sed -e 's/.*\([0-9]\{4\}\).*/\1/g') | |
mysql $1 -e "$sql" | |
mysql $1 -e "DELETE FROM changelog WHERE change_number = $migrationId" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment