New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option not to line up column attributes in schema.rb #25675

Merged
merged 2 commits into from Aug 19, 2016

Conversation

Projects
None yet
10 participants
@TimPetricola
Contributor

TimPetricola commented Jul 4, 2016

Column arguments are lined up for a given table in schema.rb. It is intended as a feature but it can get confusing in git diffs where whitespace are often added for columns with no changes. This PR adds a ActiveRecord::SchemaDumper.standardized_argument_widths = false option to avoid that.

Let's say we have an address table with the following schema:

create_table "address", force: :cascade do |t|
  t.string "zipcode", limit: 5
end

Adding another column with a longer name would also change the line for zipcode:

-   t.string "zipcode", limit: 5
+   t.string "zipcode",           limit: 5
+   t.string "extra_information", limit: 255

And generated schema.rb would now be:

create_table "address", force: :cascade do |t|
  t.string "zipcode",           limit: 5
  t.string "extra_information", limit: 255
end

By setting ActiveRecord::SchemaDumper.standardized_argument_widths to false, we would have the following diff and schema instead:

+   t.string "extra_information", limit: 255
create_table "address", force: :cascade do |t|
  t.string "zipcode", limit: 5
  t.string "extra_information", limit: 255
end
@rails-bot

This comment has been minimized.

rails-bot commented Jul 4, 2016

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @senny (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@TimPetricola TimPetricola force-pushed the TimPetricola:schema-no-standardized-column-widths branch 2 times, most recently Jul 4, 2016

@thewoolleyman

This comment has been minimized.

Contributor

thewoolleyman commented Jul 5, 2016

+1, cleaner diffs are good.

@matthewd

This comment has been minimized.

Member

matthewd commented Jul 5, 2016

Can you expand on your reasoning behind keeping the type_length alignment?

@TimPetricola

This comment has been minimized.

Contributor

TimPetricola commented Jul 8, 2016

@matthewd My bad, it should have been there. I added a second ActiveRecord::SchemaDumper.standardized_type_widths option for this. It might be worth merging both though. What do you think?

@TimPetricola

This comment has been minimized.

Contributor

TimPetricola commented Jul 29, 2016

Any update on this one ? :)

@bdewater

This comment has been minimized.

Contributor

bdewater commented Aug 2, 2016

Personally I think this should be the default 😄 but since that is probably out of the question it should be documented (perhaps here?) and of course have a changelog entry.

@prathamesh-sonpatki

This comment has been minimized.

Member

prathamesh-sonpatki commented Aug 15, 2016

I don't think the documentation should go to the migration guide because even without this patch we want to check in these files in the source control.

It should go the configuration guide here.

And we need changelog of course :)

@TimPetricola TimPetricola force-pushed the TimPetricola:schema-no-standardized-column-widths branch Aug 16, 2016

@TimPetricola

This comment has been minimized.

Contributor

TimPetricola commented Aug 16, 2016

Now with a changelog entry and some documentation in the configuration guide :) @prathamesh-sonpatki

@rafaelfranca

This comment has been minimized.

Member

rafaelfranca commented Aug 17, 2016

Could you squash your commits and rebase the branch?

@TimPetricola TimPetricola force-pushed the TimPetricola:schema-no-standardized-column-widths branch Aug 17, 2016

@TimPetricola TimPetricola force-pushed the TimPetricola:schema-no-standardized-column-widths branch to dde3bdf Aug 17, 2016

@TimPetricola

This comment has been minimized.

Contributor

TimPetricola commented Aug 17, 2016

@rafaelfranca Done. I get one error on Travis that seems unrelated though.

@maclover7

This comment has been minimized.

Member

maclover7 commented Aug 17, 2016

@TimPetricola Restarted the random failing Action Cable test job. Should be good now, hopefully. :)

@TimPetricola

This comment has been minimized.

Contributor

TimPetricola commented Aug 17, 2016

Thanks @maclover7, it fixed it :)

@rafaelfranca rafaelfranca merged commit 84cc8fd into rails:master Aug 19, 2016

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
codeclimate Code Climate has skipped analysis of this commit.
Details

rafaelfranca added a commit that referenced this pull request Aug 19, 2016

Merge pull request #25675 from TimPetricola/schema-no-standardized-co…
…lumn-widths

Option not to line up column attributes in schema.rb

@louim louim referenced this pull request Aug 20, 2016

Merged

Add rails 5 compatibility #4

@dhh

This comment has been minimized.

Member

dhh commented Aug 22, 2016

I'd prefer that we just make this the new style. No need to have this be configurable.

@rafaelfranca

This comment has been minimized.

Member

rafaelfranca commented Aug 22, 2016

Better yet. I just prepared a patch to remove the config and make it the default.

@rafaelfranca

This comment has been minimized.

Member

rafaelfranca commented Aug 22, 2016

Pushed in df84e98

rafaelfranca referenced this pull request Jun 15, 2017

Remove the SchemaDumper options and change the default behavior
Now the schema dumper by default doesn't align the types and arguments
in the ruby format anymore.

tomsabin pushed a commit to alphagov/content-tagger that referenced this pull request Jan 29, 2018

Tom Sabin
Update schema.rb formatting
Rails 5.1.0 updated the default column type/argument spacing in the
schema dump. Before then there was an option to disable the column
formatting (introduced in [1]), but the default remained the same.

However, in 5.1.0, that formatting default changed in [2]. We upgraded
from Rails 5.0.2 to 5.1.4 on 2017-11-02, but there hasn't been any
additions to the schema since 2017-10-19.

This commit is separate to the work that I am doing to introduce a
Versions table, to avoid additional changes in the schema which doesn't
introduce any _real_ change.

[1] rails/rails#25675
[2] rails/rails@df84e98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment