📝 ActiveRecord::SaneSchemaDumper removes useless/harmful whitespace from Rails’ generated `db/schema.rb` file.
Ruby
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.rubocop.yml
.travis.yml
Gemfile
LICENSE.md Update copyright year Sep 5, 2016
README.md
Rakefile
activerecord_sane_schema_dumper.gemspec

README.md

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.