GithubHelp home page GithubHelp logo

soudai-s / squasher Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jalkoby/squasher

0.0 0.0 0.0 87 KB

Squasher - squash your old migrations in a single command

License: MIT License

Ruby 97.40% HTML 2.60%

squasher's Introduction

Squasher

Build Status Code Climate Gem Version

Squasher compresses old ActiveRecord migrations. If you work on a big project with lots of migrations, every rake 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).

Attention

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

Installation

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 run rbenv 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 :tools do
  gem 'squasher', '>= 0.6.0'
  gem 'capistrano'
  gem 'rubocop'
end

Don't forget to run bundle.

To integrate squasher with your app even more do the below:

$ bundle binstub squasher
$ # and you have a runner inside the `bin` folder
$ bin/squasher

Usage

@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.rb
2012...._another_migration.rb
# and a lot of other files
2013...._adding_model_foo.rb
# few years later
2016...._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 the squasher 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 tell squasher a more detailed date, for example:

$ squasher 2016/12    # prior to December 2016
$ squasher 2016/12/19 # prior to 19 December 2016

Options

Run squasher -h or just squasher 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

Requirements

It works and was tested on Ruby 2.0+ and ActiveRecord 3.1+. It also requires a valid development configuration in config/database.yml. If an old migration inserted data (created ActiveRecord model records) you will lose this code in the squashed migration, BUT squasher 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 into config/seed.rb (the expected place for this stuff).

Changelog

All changes are located in the changelog file with contribution notes

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

squasher's People

Contributors

jalkoby avatar olivierlacan avatar mpospelov avatar ananevam avatar lime avatar finnwoelm avatar jibrankalia avatar johncarney avatar ltw avatar mlohbihler avatar killthekitten avatar petergoldstein avatar turboladen avatar tobmatth avatar tjgrathwell avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.