No release in over 3 years
Low commit activity in last 3 years
ActiveRecord::SaneSchemaDumper removes useless/harmful whitespace from Rails’ generated `db/schema.rb` files.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
>= 0
>= 0
~> 10.0
~> 3.1
= 0.27.1

Runtime

< 6, >= 5
 Project Readme

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

⚠️ WARNING · OBSOLETE ⚠️

This gem is no longer required since Rails 6 (reference commit). Rails no longer adds superfulous whitespace when dumping the schema 🙌.

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.