Skip to content

Conversation

tsvallender
Copy link
Contributor

@tsvallender tsvallender commented Nov 18, 2024

Motivation / Background

This PR allows applications with multiple databases to set a schema_format independently for each one.

I've personally found a desire for this when converting a legacy application to use the standard Rails methods one piece at a time, but it would also be useful when there is a need to move a database to use structure.sql (for some specific functionality) but no desire to do this for all databases.

Detail

The schema_format can now be set to ruby or sql in the database configuration. If this does not exist, there is no change in behaviour and the application-wide configuration is used, or the environment variable if present and appropriate.

Additional information

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@tsvallender tsvallender force-pushed the per-database-schema-format branch 2 times, most recently from 601b968 to 41359a9 Compare November 19, 2024 07:23
Copy link
Member

@flavorjones flavorjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 I'm a member of the triage team who has some familiarity with the database tasks and config code.

Currently the use of SCHEMA_FORMAT is limited to the database tasks, and I think we'd prefer to keep it out of the config classes if possible. I've made specific comments in the code.

Please also be careful about changing the method signatures of public methods (or more specifically, public methods that aren't flagged as internal-only with # :nodoc:). I've made a comment there as well.

@tsvallender tsvallender force-pushed the per-database-schema-format branch from 41359a9 to 9486dda Compare November 29, 2024 14:51
Copy link
Contributor Author

@tsvallender tsvallender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review and sorry this has taken me a little while to get back to. I've actioned all the points you've raised.

@tsvallender tsvallender force-pushed the per-database-schema-format branch from 9486dda to 8fa2802 Compare November 29, 2024 14:53
@tsvallender tsvallender force-pushed the per-database-schema-format branch 3 times, most recently from 345468d to 16a5bdf Compare December 1, 2024 15:49
@tsvallender tsvallender force-pushed the per-database-schema-format branch 2 times, most recently from e2bd1b8 to 93275d8 Compare December 9, 2024 19:43
Copy link
Contributor Author

@tsvallender tsvallender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a failing test on the changelog but I can't figure out why sorry.

@tsvallender tsvallender force-pushed the per-database-schema-format branch from 93275d8 to 804aca2 Compare December 9, 2024 20:57
@flavorjones
Copy link
Member

flavorjones commented Dec 12, 2024

@tsvallender Can I ask you to please "resolve" all the threads you've addressed? I realized that I've been procrastinating another review because of the anticipated cognitive overhead of re-reading each thread to determine if something is still needed. (It may not be obvious, but as the reviewer, github will not allow me to resolve the threads myself.)

Thanks, and sorry for my delay in responding.

@tsvallender
Copy link
Contributor Author

@tsvallender Can I ask you to please "resolve" all the threads you've addressed? I realized that I've been procrastinating another review because of the anticipated cognitive overhead of re-reading each thread to determine if something is still needed. (It may not be obvious, but as the reviewer, github will not allow me to resolve the threads myself.)

Thanks, and sorry for my delay in responding.

Apologies, I've been used to a workflow where the other person resolves them when they confirm they're happy - the permissions must be different on that repo. I've resolved them all now. Thanks for your time reviewing! 🙏

@flavorjones flavorjones added the ready PRs ready to merge label Jan 19, 2025
@tsvallender tsvallender force-pushed the per-database-schema-format branch 2 times, most recently from 989d051 to 1c1fea3 Compare February 6, 2025 18:12
@tsvallender tsvallender force-pushed the per-database-schema-format branch 4 times, most recently from 5955ba7 to 822871f Compare February 14, 2025 09:04
@tsvallender tsvallender force-pushed the per-database-schema-format branch 2 times, most recently from 379f519 to 0c961d4 Compare February 15, 2025 10:14
Checks the database configuration for a schema_format key, allowing
applications with multilpe databases to set schema format individually
for each one. Falls back to standard configuration attribute when this
is not present.
@tsvallender tsvallender force-pushed the per-database-schema-format branch from 0c961d4 to 3081fc9 Compare March 5, 2025 09:32
@tsvallender
Copy link
Contributor Author

Just rebased this and all checks are now passing, confirming the previous BuildKit issue was unrelated 👍

@eileencodes eileencodes merged commit b80bc2f into rails:main Mar 5, 2025
3 checks passed
eileencodes added a commit that referenced this pull request Mar 5, 2025
* Fix style
* Fix documentation
* Use fetch like the other methods
dhh pushed a commit that referenced this pull request Mar 5, 2025
* main:
  Cleanup #53666
  Allow per-database schema format in database config
  Move test helpers into test_helpers (#54688)
  Add `except_on:` option for validation callbacks
  Fix capture view helper to pass keyword arguments
  Stop generating bundler binstub:
  Fix channel generator import statement:
  Optimize `String#parameterize`
  Add anchor links to FormOptionsHelper [ci skip]
  Fix creating fsm visualizer with lazy routes
schmijos added a commit to schmijos/rails that referenced this pull request May 13, 2025
Considering how we go forward in rails#53666, this has been an oversight when introducing the `SCHEMA_FORMAT` environment variable.
salzig pushed a commit to salzig/rails that referenced this pull request Sep 18, 2025
Considering how we go forward in rails#53666, this has been an oversight when introducing the `SCHEMA_FORMAT` environment variable.
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