Skip to content

Instantly share code, notes, and snippets.

@bf4
Created November 12, 2015 16:07
Show Gist options
  • Save bf4/397d025b7243c69b99fd to your computer and use it in GitHub Desktop.
Save bf4/397d025b7243c69b99fd to your computer and use it in GitHub Desktop.
Squash Rails migrations in this one easy step
#!/usr/bin/env bash
git ls-files db/migrate/*.rb | sort | tail -1 | \
ruby -e "schema_version=STDIN.read[/\d+/]; init_schema=%(db/migrate/#{schema_version}_init_schema.rb);
%x(git rm -f db/migrate/*.rb;
mkdir db/migrate;
git mv db/schema.rb #{init_schema};
rake db:migrate;
git add db/schema.rb; git commit -m 'Squashed migrations')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment