Skip to content
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

Added a shared section to config/database.yml that will be loaded for all envs #28896

Merged
merged 1 commit into from Apr 27, 2017

Conversation

pschambacher
Copy link
Contributor

Summary

I've discovered this commit from @dhh to have a shared section for secrets.yml today at @claudiob 's talk at RailsConf.
I really like the idea and since all the database.yml that I'm working with have some & <<: * shenanigans, I thought it would be nice to make it available there as well.

@@ -0,0 +1,17 @@
require "yaml"

module YAML
Copy link
Member

Choose a reason for hiding this comment

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

We should not add a monkey patch to implement this feature. We don't want to implement a new version of the YML specification. Could you move it back to the previous implementation and only add support to the database configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sure can but fear that we might want to expand this to more yml files over time. Would it be OK if I make it a module of its own rather than a monkey patch? ActiveSupport::YamlWithSharedSection.load?

Copy link
Member

Choose a reason for hiding this comment

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

If that is the case we can do it, but right now I prefer duplication. This is not something that I personally want to spread to more yaml files. I also don't want to give users access to this feature so as harder it is to do, better for us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I'll make the change

@pschambacher
Copy link
Contributor Author

Changes applied.

@rafaelfranca rafaelfranca merged commit 28cd12c into rails:master Apr 27, 2017
rafaelfranca added a commit that referenced this pull request Apr 27, 2017
Added a shared section to config/database.yml that will be loaded for all envs
@rafaelfranca
Copy link
Member

Backported in 92278a5

@pschambacher pschambacher deleted the load_with_shared branch April 27, 2017 15:19
@pschambacher
Copy link
Contributor Author

Much appreciated 🙇 🙏

@matthewd
Copy link
Member

This seems to conflict conceptually with #28095

@pschambacher
Copy link
Contributor Author

Hmm yes my change would not affect those nested keys inside of environments.
Maybe letting the shared key alone rather than use delete so it can be recovered when loading the nested configuration?

@claudiob
Copy link
Member

@matthewd I wonder if, given that conflict, we might be better off not backporting this to 5.1 and instead letting it ship with 5.2 with full support for #28095

@rafaelfranca what do you think? Seems like a new feature that we are adding to a RC.

rafaelfranca added a commit that referenced this pull request Apr 27, 2017
This reverts commit 92278a5.

This seems to conflict conceptually with #28095 and it is a new feature
after the RC.
@rafaelfranca
Copy link
Member

@claudiob totally agree. I'll revert the backport.

@matthewd I'm not strong about this feature and I'm leaning to the side of reverting it entirely. I personally don't like that we are creating a new yaml dialect. WDYT?

@dhh
Copy link
Member

dhh commented Apr 27, 2017 via email

@pschambacher
Copy link
Contributor Author

Regarding 5.1-5.2, I intended this for 5.2 so all cool 😊
@dhh do you mean moving from loading the YAML to where ActiveRecord reads the configuration with the environment?

@matthewd
Copy link
Member

matthewd commented May 8, 2017

Yeah, my concern is that "shared" feels a rather blunt instrument in a three-level world: do we mean a) these values are shared by all connections in all environments, or b) these are entire connection definitions which are shared across environments? Or do we actually want to c) specify values that are shared by all connections within an environment?

To me, it starts to get involved enough that the explicitness of YAML's built-in syntax, where the data gets explicitly labelled and then referenced, seems more predictable.

If we can decide on an overwhelmingly-more-useful interpretation between the three above, though, there are obviously advantages of supporting the same mechanism we do in secrets. It does feel like it belongs a bit further up, where AR uses database_configuration, though... inside resolve_all, perhaps.

@pschambacher
Copy link
Contributor Author

I actually tend to think that the shared concept would bring a lot to the other PR. The sample yaml given in the PR would simply become:

shared:
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  primary:
    database: db/development.sqlite3
  readonly:
    database: db/readonly.sqlite3

It looks concise and clear to me.
Based on your feedback and dhh's one, I'll make a follow-up PR to move the logic where AR is using database_configuration.

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.

None yet

6 participants