Skip to content

Instantly share code, notes, and snippets.

@dovys
Last active August 29, 2015 14:16
Show Gist options
  • Save dovys/e38adbd27aa8d28cf66c to your computer and use it in GitHub Desktop.
Save dovys/e38adbd27aa8d28cf66c to your computer and use it in GitHub Desktop.
Undo Groups migrations
#!/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