Skip to content

Instantly share code, notes, and snippets.

@mberrueta
Forked from bf4/bin-squash_migrations
Created May 10, 2018 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mberrueta/16b423c28c20bd94bae29aed5fd3ad9c to your computer and use it in GitHub Desktop.
Save mberrueta/16b423c28c20bd94bae29aed5fd3ad9c 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