aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/connection_specification.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix typo in loading error messageyuuji.yaginuma2017-10-091-1/+1
| | | | s/Action Record/Active Record/
* Distinguish missing adapter gems from load errors within the adapterJeremy Daer2017-10-081-3/+15
| | | | | | | | * When the adapter is missing, raise an exception that points out config typos and missing Gemfile entries. (We can assume that a non-builtin adapter was used since these are always available.) * When loading an adapter raises a LoadError, prefix its error message to indicate that the adapter is likely missing an optional dependency.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Allow 3-level DB configs to group connections by environmentMatthew Draper2017-02-221-0/+9
| | | | [Arthur Nogueira Neves & Matthew Draper]
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-2/+2
|
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-46/+46
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* Fix broken alignments caused by auto-correct commit 411ccbdRyuta Kamizono2016-08-101-2/+4
| | | | Hash syntax auto-correcting breaks alignments. 411ccbdab2608c62aabdb320d52cb02d446bb39c
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-56/+56
|
* remove redundant curlies from hash argumentsXavier Noria2016-08-061-6/+4
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-5/+5
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Add to_hash to specificationArthur Neves2016-05-251-0/+4
|
* Remove `name` from `establish_connection`Arthur Neves2016-05-241-9/+3
| | | | | Instead of passing a separete name variable, we can make the resolver merge a name on the config, and use that before creating the Specification.
* Move establish_connection to handlerArthur Neves2016-05-241-0/+4
|
* s/specification_id/specification_nameArthur Neves2016-05-051-6/+6
|
* Better code readabilityArthur Neves2016-05-051-1/+1
|
* Use spec key, when given as spec_idArthur Neves2016-05-051-1/+8
|
* Refactor connection handlerArthur Neves2016-05-051-5/+5
| | | | | | | | | | | | | | | ConnectionHandler will not have any knowlodge of AR models now, it will only know about the specs. Like that we can decouple the two, and allow the same model to use more than one connection. Historically, folks used to create abstract AR classes on the fly in order to have multiple connections for the same model, and override the connection methods. With this, now we can override the `specificiation_id` method in the model, to return a key, that will be used to find the connection_pool from the handler.
* Remove the assumption of schema in DATABASE_URLJeremy Baker2016-02-041-1/+1
| | | | | | | | | | | | | | | | | If you set the DATABASE_URL environment variable to `mydatabase` by accident, you end up getting a series of errors that are hard to trace. For example: ``` warning: already initialized constant ActiveRecord::Base::OrmAdapter ``` Turns out the cascade of errors is due to the error raised by `.tr` being called on `nil`. This commit makes sure that `scheme` is set before calling `.tr` on it. My previous iteration used `@uri.scheme.try(:tr, '-', '_')` but using the `&&` logical operator is a fair bit faster: http://stackoverflow.com/questions/26655032/try-vs-performance With this change, the error message becomes much more understandable: ``` FATAL: database "mydatabase" does not exist (ActiveRecord::NoDatabaseError) ```
* Remove legacy mysql adapterAbdelkader Boudih2015-12-171-1/+1
|
* Remove deprecated access to connection specification using a string acessor.Rafael Mendonça França2015-01-041-20/+1
| | | | Now all strings will be handled as a URL.
* Wrap code snippets in +, not backticks, in sdocclaudiob2014-11-201-1/+1
| | | | | | | | I grepped the source code for code snippets wrapped in backticks in the comments and replaced the backticks with plus signs so they are correctly displayed in the Rails documentation. [ci skip]
* edit pass over all warningsXavier Noria2014-10-281-1/+1
| | | | | | | | | | | | | | | This patch uniformizes warning messages. I used the most common style already present in the code base: * Capitalize the first word. * End the message with a full stop. * "Rails 5" instead of "Rails 5.0". * Backticks for method names and inline code. Also, converted a few long strings into the new heredoc convention.
* let's warn with heredocsXavier Noria2014-10-281-2/+7
| | | | | | | | | | | | The current style for warning messages without newlines uses concatenation of string literals with manual trailing spaces where needed. Heredocs have better readability, and with `squish` we can still produce a single line. This is a similar use case to the one that motivated defining `strip_heredoc`, heredocs are super clean.
* use tr instead of gsub when possibleAdrian Rangel2014-10-011-1/+1
|
* use the uri parser so that newer version of Ruby workAaron Patterson2014-08-071-1/+1
|
* Fix documentation typo in ConnectionSpecification::Resolve.speca3gis2014-07-241-1/+1
|
* Fixes #16265a3gis2014-07-241-1/+1
|
* Parsing DATABASE_URI, use URI#hostname: it's smarter about IPv6Matthew Draper2014-06-141-1/+1
| | | | Fixes #15705.
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2014-04-181-2/+2
|\
| * [ci skip] Use valid current config in exampleschneems2014-04-151-2/+2
| | | | | | `reaping_frequency` is used in Active Record `reap_frequency` is not
* | Drop in @jeremy's new database.yml template textMatthew Draper2014-04-091-1/+1
| | | | | | | | | | In passing, allow multi-word adapters to be referenced in a URL: underscored_name must become hyphened-name.
* | Give a deprecation message even when the lookup failsMatthew Draper2014-04-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | If the supplied string doesn't contain a colon, it clearly cannot be a database URL. They must have intended to do a key lookup, so even though it failed, give the explanatory deprecation warning, and raise the exception that lists the known configs. Conveniently, this also simplifies our logical behaviour: if the string matches a known configuration, or doesn't contain a colon (and is therefore clearly not a URL), then we output a deprecation warning, and behave exactly as we would if it were a symbol.
* | Merge pull request #14569 from matthewd/sqlite_relative_deprecatedRafael Mendonça França2014-04-031-17/+30
|\ \ | | | | | | | | | | | | | | | | | | Revise 'sqlite3:' URL handling for smoother upgrades Conflicts: activerecord/CHANGELOG.md
| * | Complete change of `sqlite3:///` path handlingMatthew Draper2014-04-031-15/+1
| | | | | | | | | | | | That which was now relative is now absolute.
| * | Revise 'sqlite3:' URL handling for smoother upgradesMatthew Draper2014-04-031-18/+45
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Restore the 4.0 behaviour for 'sqlite3:///', but deprecate it. We'll change to the absolute-path interpretation in 4.2. The current "correct" spellings for in-memory, relative, and absolute URLs, respectively, are: sqlite3::memory: sqlite3:relative/path sqlite3:/full/path Substantially reverses/defers fbb79b517f3127ba620fedd01849f9628b78d6ce. Uncovered by @guilleiguaran while investigating #14495, though that sounds like a different issue.
* | Avoid including DB details in exception messagesMatthew Draper2014-04-031-1/+1
| | | | | | | | | | The keys are quite sufficient; we shouldn't be throwing passwords around.
* | Avoid a spurious deprecation warning for database URLsMatthew Draper2014-04-031-23/+27
|/ | | | | | | | | | | | | | | | | | This is all about the case where we have a `DATABASE_URL`, and we have a `database.yml` present, but the latter doesn't contain the key we're looking for. If the key is a symbol, we'll always connect to `DATABASE_URL`, per the new behaviour in 283a2edec2f8ccdf90fb58025608f02a63948fa0. If the key is a string, on the other hand, it should always be a URL: the ability to specify a name not present in `database.yml` is new in this version of Rails, and that ability does not stretch to the deprecated use of a string in place of a symbol. Uncovered by @guilleiguaran while investigating #14495 -- this actually may be related to the original report, but we don't have enough info to confirm.
* Allow custom JDBC urlsschneems2014-03-141-2/+2
| | | | mitigates #14323
* Ensure Active Record connection consistencyschneems2014-01-091-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently Active Record can be configured via the environment variable `DATABASE_URL` or by manually injecting a hash of values which is what Rails does, reading in `database.yml` and setting Active Record appropriately. Active Record expects to be able to use `DATABASE_URL` without the use of Rails, and we cannot rip out this functionality without deprecating. This presents a problem though when both config is set, and a `DATABASE_URL` is present. Currently the `DATABASE_URL` should "win" and none of the values in `database.yml` are used. This is somewhat unexpected to me if I were to set values such as `pool` in the `production:` group of `database.yml` they are ignored. There are many ways that active record initiates a connection today: - Stand Alone (without rails) - `rake db:<tasks>` - ActiveRecord.establish_connection - With Rails - `rake db:<tasks>` - `rails <server> | <console>` - `rails dbconsole` We should make all of these behave exactly the same way. The best way to do this is to put all of this logic in one place so it is guaranteed to be used. Here is my prosed matrix of how this behavior should work: ``` No database.yml No DATABASE_URL => Error ``` ``` database.yml present No DATABASE_URL => Use database.yml configuration ``` ``` No database.yml DATABASE_URL present => use DATABASE_URL configuration ``` ``` database.yml present DATABASE_URL present => Merged into `url` sub key. If both specify `url` sub key, the `database.yml` `url` sub key "wins". If other paramaters `adapter` or `database` are specified in YAML, they are discarded as the `url` sub key "wins". ``` ### Implementation Current implementation uses `ActiveRecord::Base.configurations` to resolve and merge all connection information before returning. This is achieved through a utility class: `ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig`. To understand the exact behavior of this class, it is best to review the behavior in activerecord/test/cases/connection_adapters/connection_handler_test.rb though it should match the above proposal.
* Fix AR connection resolver docs to return a hash with string keys [ci skip]Carlos Antonio da Silva2014-01-061-1/+1
|
* Fix typo [ci skip]Carlos Antonio da Silva2014-01-061-1/+1
|
* Allow "url" sub key in database.yml configurationschneems2013-12-301-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently a developer can pass in a YAML configuration that fully specifies connection information: ``` production: database: triage_production adapter: password pool: 5 ``` They can also pass in a string that specifies a connection URL directly to an environment key: ``` production: postgresql://localhost/foo ``` This PR allows the use of both a connection url and specifying connection attributes via YAML through the use of the "url" sub key: ``` production: url: postgresql://localhost/foo pool: 3 ``` This will allow developers to inherit Active Record options such as `pool` from `&defaults` and still use a secure connection url such as `<%= ENV['DATABASE_URL'] %>`. The URL is expanded into a hash and then merged back into the YAML hash. If there are any conflicts, the values from the connection URL are preferred. Talked this over with @josevalim
* [ci skip] ConnectionSpecification::Resolver Docsschneems2013-12-301-14/+80
| | | | | Document the internal interfaces of `ConnectionSpecification::Resolver` Change method name from `config` to `env` to better match the most common use case.
* Extract db url connection logic to classschneems2013-12-291-34/+79
|
* Deprecate use of string in establish_connection as connection lookupJosé Valim2013-12-241-9/+16
|
* Only build a ConnectionSpecification if requiredJosé Valim2013-12-241-26/+28
|
* Fix build failures related to the new ENV options in ymlJosé Valim2013-12-241-3/+3
|