Option not to line up column attributes in schema.rb

30 views
Skip to first unread message

Tim Petricola

unread,
Jul 4, 2016, 11:20:04 PM7/4/16
to Ruby on Rails: Core
schema.rb git diff are often harder to read as adding a column or argument could add/remove whitespace for other columns definitions.

Let's say I have a `users` table with a `first_name` column:

create_table "users", force: :cascade do |t|
  t.string "first_name", null: false
end


If I add another column with a `limit`, whitespaces will be added to my schema for the `first_name` line as well:

create_table "users", force: :cascade do |t|
  t.string "first_name",           null: false
  t.string "zipcode",    limit: 5, null: false
end


I understand it is intended as a feature but it would be nice to offer an opt-out option to generate the following schema instead:

create_table "users", force: :cascade do |t|
  t.string "first_name", null: false
  t.string "zipcode", limit: 5, null: false
end

I have some working code for this option, I'm waiting for your thoughts before doing a PR.

Jason Fleetwood-Boldt

unread,
Jul 5, 2016, 7:44:26 AM7/5/16
to rubyonra...@googlegroups.com

Yes please :+1:

Dealing with that cruft mismatch in schema.rb is a headache --- would defiantly speed up developer productivity if we figured out the reasons why different developers' systems produce slightly different files (this being one of them) and killed those nuances so my schema.rb didn't change itself even when there are no schema changes.

It is definitely something that does not make me :happy_face: and Matz said Ruby was supposed to make me happy. 

-Jason


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

If you'd like to reply by encrypted email you can find my public key on jasonfleetwoodboldt.com (more about setting GPG: https://gpgtools.org

Xavier Noria

unread,
Jul 5, 2016, 8:09:15 AM7/5/16
to rubyonrails-core
Positive over here. People may occasionally have a look at db/schema.rb, but it's main use case is to automate stuff.

Personally, I wouldn't even make it configurable in this case, we are not talking about generating a non-readable dump. Some people would even write it like that if it was their code. A matter of preference, no big deal.


Prem Sichanugrist

unread,
Jul 5, 2016, 8:13:35 AM7/5/16
to rubyonra...@googlegroups.com
+1

I had this idea too. It's annoying when looking at diff when something changes and it's not obvious. 

If someone wants to take a stab at it, please feel free. 

-Prem

On Jul 5, 2016, at 8:08 AM, Xavier Noria <f...@hashref.com> wrote:

Positive over here. People may occasionally have a look at db/schema.rb, but it's main use case is to automate stuff.

Personally, I wouldn't even make it configurable in this case, we are not talking about generating a non-readable dump. Some people would even write it like that if it was their code. A matter of preference, no big deal.


Reply all
Reply to author
Forward
0 new messages