aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/database_configurations.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix database.yml mergingeileencodes2018-04-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ok so apparently you can not just have a `default:` that manually is merged in with YAML but you can also have a special "shared" config that is automatically merged. Example: ``` shared: adapter: mysql2 host: <%= ENV["DB_HOST"] || "localhost" %> username: root connect_timeout: 0 pool: 100 reconnect: true development: database: development_db adapter: mysql2 ``` To fix, only create a DatabaseConfig object when an adapter, database, or URL are present. The merging behavior for `shared` doesn't work with a 3-tier config. I don't think it worked before this change either - since Rails doesn't know which point to merge it in. That's something we may have to fix with the refactoring I'm working on.
* Fix two-level database configurations with URLsEugene Kenny2018-03-311-1/+1
| | | | | | | | | An entry in `ActiveRecord::Base.configurations` can either be a connection spec ("two-level") or a hash of specs ("three-level"). We were detecting two-level configurations by looking for the `database` key, but the database can also be specified as part of the `url` key, which meant we incorrectly treated those configurations as three-level.
* Remove shadowing variable warningAndrew White2018-03-301-2/+2
|
* Refactor configs_for and friendseileencodes2018-03-211-0/+63
Moves the configs_for and DatabaseConfig struct into it's own file. I was considering doing this in a future refactoring but our set up forced me to move it now. You see there are `mattr_accessor`'s on the Core module that have default settings. For example the `schema_format` defaults to Ruby. So if I call `configs_for` or any methods in the Core module it will reset the `schema_format` to `:ruby`. By moving it to it's own class we can keep the logic contained and avoid this unfortunate issue. The second change here does a double loop over the yaml files. Bear with me... Our tests dictate that we need to load an environment before our rake tasks because we could have something in an environment that the database.yml depends on. There are side-effects to this and I think there's a deeper bug that needs to be fixed but that's for another issue. The gist of the problem is when I was creating the dynamic rake tasks if the yaml that that rake task is calling evaluates code (like erb) that calls the environment configs the code will blow up because the environment is not loaded yet. To avoid this issue we added a new method that simply loads the yaml and does not evaluate the erb or anything in it. We then use that yaml to create the task name. Inside the task name we can then call `load_config` and load the real config to actually call the code internal to the task. I admit, this is gross, but refactoring can't all be pretty all the time and I'm working hard with `@tenderlove` to refactor much more of this code to get to a better place re connection management and rake tasks.