Coder Social home page Coder Social logo

db-refresher's Introduction

refresher - A simble database schema cache refresh

Tl;dr

Refresher allows you to create user and database with just only single command: rake db_refresher. Then you can continue with rake db:migrate

Installation and Usage

Add into your Gemfile:

gem 'refresher'

Then run

rake db_refresher; rake db:migrate

You may want to run db:seeds too if you have any.

Story

Imagine you are prototyping a Rails application with much table (let say 30+ tables) at the first time. You might end up with this:

20151210051128_create_orders.rb
20151210113138_add_payment_commit_time_to_orders.rb
20151213090513_remove_payment_hash_from_order.rb
20151214042001_add_payment_to_order.rb
20151214051032_create_payments.rb

There might be so much add and remove migration file. In fact, you are prototyping so database schema is expected to change in this early stage. Also, there is no single overview about current schema in migration files. You might need to see db/schema.rb or use model annotation tools like annotate to get a summary of current schema/table.

When prototyping, you might want to see everything about a table in a single migration file. You might only want create_orders.rb in contrast of four migration files describing a single table. Unfortunately, you can't simply add field to create_orders then run rake db:migrate because Rails won't notice the different of migration file if the migration timestamp id has been existed in db. You must db:rollback and then db:migrate again, for every single migration you change (but has been persisted to db).

Another way is to just drop the entire db, then create the db again, then run the migration (rake db:drop db:create db:migrate). That is okay if you are prototyping 10 tables, but imagine you are prototyping with 60 tables, and you only want to change last 5 tables, it might take 20+ seconds just to drop and populate 60 tables. In this case, perhaps rollback is better.

With refresher, you can populate db with SQL cache, so let say your latest checkpoint for you is migration id 2015, and you change 2016

2014_create_a
2015_create_b    <-- latest schema in cache
2016_create_c
2017_create_d

refresher With Cache

rake db:refresh

rake db:refresh_invalidate_cache

rake db:refresh_persist_cache

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.