Coder Social home page Coder Social logo

kickbooster / activerecord_sane_schema_dumper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mirego/activerecord_sane_schema_dumper

0.0 1.0 0.0 18 KB

:memo: ActiveRecord::SaneSchemaDumper removes useless/harmful whitespace from Rails’ generated `db/schema.rb` file.

Home Page: http://open.mirego.com

License: BSD 3-Clause "New" or "Revised" License

Ruby 100.00%

activerecord_sane_schema_dumper's Introduction

ActiveRecord::SaneSchemaDumper

ActiveRecord::SaneSchemaDumper modifies the behavior of Rails’ ActiveRecord::SchemaDumper so that the generated db/schema.rb file doesn’t contain any useless/harmful whitespace column alignment.

Gem Version Build Status

Installation

Add this line to your application’s Gemfile in your development group:

group :development do
  gem 'activerecord_sane_schema_dumper'
end

Usage

The gem modifies the behavior of Rails’ rake db:schema:dump task. This task is part of Rails migrations process to ensure that db/schema.rb stays in-sync with your local database.

It removes all useless whitespace that Rails adds so adding/modifying/removing columns from your tables only touches relevant lines (because other table lines do not try to stay aligned).

Before

# db/schema.rb
create_table "event_data", force: true do |t|
  t.string   "event_external_id"
  t.json     "data",              default: {}
  t.datetime "created_at",                     null: false
  t.datetime "updated_at",                     null: false
end

But what happens if I remove the data column and regenerate db/schema.rb? Here’s the resulting diff:

   create_table "event_data", force: true do |t|
     t.string   "event_external_id"
-    t.datetime "created_at",                     null: false
-    t.datetime "updated_at",                     null: false
-    t.json     "data",              default: {}
+    t.datetime "created_at",        null: false
+    t.datetime "updated_at",        null: false
   end

We’ve removed the data column but created_at and updated_at lines are affected too. This is not good.

After

# db/schema.rb
create_table "event_data", force: true do |t|
  t.string "event_external_id"
  t.json "data", default: {}
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
end

If I remove the data column and regenerate the db/schema.rb file, only the relevant line will be touched:

   create_table "event_data", force: true do |t|
     t.string "event_external_id"
-    t.json "data", default: {}
     t.datetime "created_at", null: false
     t.datetime "updated_at", null: false
   end

One removed column, one affected line in the table definition. Much better.

License

ActiveRecord::SaneSchemaDumper is © 2014-2016 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.

About Mirego

Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.

We also love open-source software and we try to give back to the community as much as we can.

activerecord_sane_schema_dumper's People

Contributors

remi avatar louim avatar

Watchers

James Cloos 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.