Schema.rb generation

Running migrations on different environments (sql encodings) create a different schema.rb file.

1 Like

To add to this, there is no way to reconcile small differences between different developers’ local databases, which end up creating edit wars in schema.rb (for example, a common thing I see at work is t.text "parameters", limit: 16777215 vs t.text "parameters", size: :medium)

We’ve added these rake tasks to our codebase to resolve these issues migrate_enhancements.rake · GitHub

Would love if it were part of Rails.

@ghiculescu That sounds like a really interesting PR you could make :wink:

Let me know if you want a hand shepherding it through the process! It would be great if you could get public credit for that work.

@Betsy_Haibel sure. Happy to give it a try.

The behaviour we have is quite strict, and quite specific to our needs.

  • Only works for postgres
  • Only works with structure.sql
  • Totally blocks db:migrate if you don’t have the right setup

I imagine for it to be in Rails you’d want it to be much more generic and less strict, or are you suggesting I make a PR that contributes exactly what’s in that gist?

I think that it might be helpful to make it opt-in, or something that only applies if you’re using structure.sql and postgres. (Or both!)

But tbh, those are the only significant modifications I’d make.

(I’m speaking here as someone who uses structure.sql and could use it verbatim, though.)

1 Like

Cool. I put up a draft PR (i hope that’s okay): Structure.sql: only dump migrations that exist in the codebase by ghiculescu · Pull Request #39209 · rails/rails · GitHub

Hurrah! While I can’t speak for the core team, I’m personally glad that you stepped up with a draft and were organized about presenting what you saw as open questions.

Thanks for the nudge!

Is a draft PR a good way to get feedback or should I just finish it off and see what happens?

I’d say finish it off and see what happens. :slight_smile: I do know that the maintainers are feeling a little overwhelmed right now, so I’m not sure how fast they’ll be able to give you feedback, but it seems like a tightly scoped, easy-to-read PR to me. That ought to help them out a lot.

I don’t blame them. This initiative is great but seems to be getting a bit too popular :slight_smile:

@Betsy_Haibel I think I’ve got a green build (yay). If you have a few minutes, I’d love if you could take a look at the questions I have on there and let me know if you have any opinions on them, before I take it out of draft mode.

Draft PR up for the edit wars over schema.rb (the original purpose of this thread) here: Preferred database version by ghiculescu · Pull Request #39237 · rails/rails · GitHub

1 Like