Skip to content

Comments

Switch trailing commas in structure.sql to leading#43414

Closed
mlarraz wants to merge 2 commits intorails:mainfrom
mlarraz:leading_comma_versions
Closed

Switch trailing commas in structure.sql to leading#43414
mlarraz wants to merge 2 commits intorails:mainfrom
mlarraz:leading_comma_versions

Conversation

@mlarraz
Copy link
Contributor

@mlarraz mlarraz commented Oct 8, 2021

Summary

Changes the formatting of the migration versions to reduce merge conflicts.

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
('20210924183850'),
('20211008165610'),
('20211108235701');
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. By changing the formatting slightly, this is no longer an issue:

INSERT INTO "schema_migrations" (version) VALUES
('20210924183850')
,('20211008165610')
,('20211108235701')
;
INSERT INTO "schema_migrations" (version) VALUES
('20190924183850')
,('20191008165610')
,('20191108235701')
+,('20191118181905')
;

In both cases this is valid SQL with no functional difference.

@ghiculescu
Copy link
Member

@eileencodes this might help a lot with the merge conflict question you had.

@eileencodes
Copy link
Member

That's an interesting solution to the problem. There's a couple things we need to do though before we can merge this.

  1. There needs to be a CHANGELOG entry for active record.
  2. How disruptive will this be to applications? Is there any value in making this configurable or is that overkill?

@mlarraz
Copy link
Contributor Author

mlarraz commented Oct 11, 2021

  1. There needs to be a CHANGELOG entry for active record.

Done

  1. How disruptive will this be to applications? Is there any value in making this configurable or is that overkill?

We're running this internally as a monkey patch and aside from the one-time cost of the first structure dump changing all the existing entries, it's been pretty invisible.

@matthewd
Copy link
Member

Interesting indeed! While that definitely means the same thing to the computer, it feels like a (small) experience downgrade for the human (who I think will still need to edit this section to resolve conflicts, at least sometimes, even with the spurious semicolon changes removed).

What if we reversed the sort order instead? 🤔

@rails-bot
Copy link

rails-bot bot commented Jan 9, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Jan 9, 2022
@ghiculescu
Copy link
Member

ghiculescu commented Jan 9, 2022

What if we reversed the sort order instead? 🤔

Tested this monkey patch:

# https://github.com/rails/rails/pull/43414
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

It seems to work pretty well.

Edit: after running that monkey patch for about a month, I've made a PR to upstream: #44363

@rails-bot rails-bot bot removed the stale label Jan 9, 2022
ghiculescu added a commit to ghiculescu/rails that referenced this pull request Feb 8, 2022
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]>
@mlarraz mlarraz deleted the leading_comma_versions branch February 8, 2022 23:11
null-hype pushed a commit to public-rant/rails that referenced this pull request Feb 17, 2022
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants