Reverse the order of INSERT statements in structure.sql dumps#44363
Reverse the order of INSERT statements in structure.sql dumps#44363byroot merged 1 commit intorails:mainfrom
INSERT statements in structure.sql dumps#44363Conversation
f1e5aae to
a027a9a
Compare
This comment was marked as resolved.
This comment was marked as resolved.
|
Can you rebase? You have a conflict on the CHANGELOG. Other than that I'm 💯 on this PR. |
a027a9a to
b050b00
Compare
This was suggested as a better fix in rails#43414. The goal is to decrease merge conflicts that often come at the bottom due to the semi colon placement. We've been running with a monkey patch for it for about a month, and can confirm, it's definitely an improvement. So I'm making this as an alternative suggestion to rails#43414 Adding @mlarraz as a co-author - thanks for the original inspiration. Co-authored-by: @mlarraz <[email protected]>
b050b00 to
7c8ac6c
Compare
|
Alright, I finally got it green. |
|
In every major rails project we will now scroll first down to the end of the structure file and then a few pages up to see the latest inserted versions. Sorry to say - i know everyone is opinionated about everything - but while i also do not like leading commas that would have been the better option for this. Printing the order inverse is imho cumbersome. If i tail the file i want to see the newest stuff last. |
|
Is there a way to override this jarring new default? |
|
You could monkey patch this: module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter
def insert_versions_sql(versions)
if versions.is_a?(Array)
super(versions.reverse)
else
super
end
end
end
end
end |
Or you could revert, and then YOU could monkey patch. |
|
I also dislike this change. Maybe it's better in niche situations, but for everyday use, it's worse. It's also incredibly bad for upgrading Rails, when there's already so much changing, and then we also have to see hundreds of lines of diffs in the DB files. In my opinion, this is almost a complete negative. But, I suppose this does stick to Rails's and Ruby's conventions of inconveniencing developers and making things harder if it saves 1 or 2 characters :/ |
A project I am working on has 1833 migrations. It took 61 page-ups and will only increase. 🤦 |
Summary
Today every new migration added adds a new line here, but also requires moving the semicolon from what was previously the most recent line:
INSERT INTO "schema_migrations" (version) VALUES ('20190924183850'), ('20191008165610'), +('20191108235701'), -('20191108235701'); +('20191118181905');This leads to merge conflicts if lots of migrations are being added at the same.
How this PR came about
The fix in this PR was suggested as a better fix by @matthewd in #43414.
We've been running with a monkey patch for it for about a month, and can confirm, it's definitely an improvement. So I'm making this as an alternative suggestion to #43414
Adding @mlarraz as a co-author - thanks for the original inspiration.
For reference #3477 added the original sorting logic.