- Notifications
You must be signed in to change notification settings - Fork57
Squasher - squash your old migrations in a single command
License
jalkoby/squasher
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Squasher compresses old ActiveRecord migrations. If you work on a big project with lots of migrations, everyrake db:migrate
might take a few seconds, or creating of a new database might take a few minutes. That's because ActiveRecord loads all those migration files. Squasher removes all the migrations and creates a single migration with the final database state of the specified date (the new migration will look like a schema).
Prior to 0.6.2 squasher could damage your real data as generate "force" tables. Please upgrade to 0.6.2+ & manually clean "force" tag from the init migration
You don't have to add it into your Gemfile. Just a standalone installation:
$ gem install squasher
@note if you use Rbenv don't forget to runrbenv rehash
.
If you want to share it with your rails/sinatra/etc app add the below:
# Yep, the missing group in most Gemfiles where all utilities should be!group:toolsdogem'squasher','>= 0.6.0'gem'capistrano'gem'rubocop'end
Don't forget to runbundle
.
To integratesquasher
with your app even more do the below:
$ bundle binstub squasher$ # and you have a runner inside the `bin` folder$ bin/squasher
@note stop all preloading systems if there are present (spring, zeus, etc)
Suppose your application was created a few years ago.%app_root%/db/migrate
folder looks like this:
2012...._first_migration.rb2012...._another_migration.rb# and a lot of other files2013...._adding_model_foo.rb# few years later2016...._removing_model_foo.rb# and so on
Storing these atomic changes over time is painful and useless. It's time to archive this history. Once you install the gem you can run thesquasher
command. For example, you want to compress all migrations which were created prior to the year 2017:
$ squasher 2017 # rails 3 & 4$ squasher 2017 -m 5.0 # rails 5+
You can tellsquasher
a more detailed date, for example:
$ squasher 2016/12 # prior to December 2016$ squasher 2016/12/19 # prior to 19 December 2016
Runsquasher -h
or justsquasher
to see how you can use squasher:
- in sql schema rails app
- in rails 5+ app
- inside an engine
- in "dry" mode
- in "reuse" mode
It works and was tested on Ruby 2.0+ and ActiveRecord 3.1+. It also requires a valid development configuration inconfig/database.yml
.If an old migration inserted data (created ActiveRecord model records) you will lose this code in the squashed migration,BUTsquasher
will ask you to leave a tmp database which will have all data that was inserted while migrating. Using this database you could add that data as another migration, or intoconfig/seed.rb
(the expected place for this stuff).
All changes are located inthe changelog file with contribution notes
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
About
Squasher - squash your old migrations in a single command