Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes support for database alias on database.yml #5579

Closed
wants to merge 1 commit into from

2 participants

Kristopher Murata Piotr Sarnacki
Kristopher Murata

Until Rails 3.1 we could use a string to copythe same config from another database config:

development:
  adapter: postgresql
  encoding: utf8
  database: test_development
  host: localhost

production:
  development

This stopped working when @tenderlove used his refactoring sword to slice the establish_connection logic on commit 2a9a8ad

I don't know if this is the right approach to fix this issue or even if it's a issue, if you guys accept it I need to apply this patch on master as well.

Kristopher Murata krsmurata Fixes support for database alias on database.yml
Until Rails 3.1 we could use a string to copy
the same config from another database config:

development:
	...

production:
  development

This stopped working when @tenderlove used
his refactoring sword to slice the
establish_connection logic on commit
2a9a8ad
aa584af
Piotr Sarnacki
Collaborator

I guess you could just use standard yml way of doing this:

production: &production
  username: root

development: *production
Piotr Sarnacki
Collaborator

@krsmurata I've confirmed with some of the core team members and this is the behavior that was rather unknown for the most of developers, so it's rather not worth it to maintain it having in mind that there is already widely known pattern in YAML. Usually it's used like that:

defaults: &defaults
  adapter: postgresql
  username: root
  password:
  encoding: utf8

development:
  database: app_development
  <<: *defaults

Thanks for the pull request, though!

Piotr Sarnacki drogus closed this
Kristopher Murata

Thanks for the feedback @drogus

Yeah, I was quite sure that it wasn't a bug since the correct notation for repeated notes on YAML is using &string and then using it as *string, but it somehow breaks an exiting not so known feature.

I agree it's not worth maintaining it if it's obsolete, maybe should be nice to have an entry on the CHANGELOG notifying about this change on 3.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2012
  1. Kristopher Murata

    Fixes support for database alias on database.yml

    krsmurata authored
    Until Rails 3.1 we could use a string to copy
    the same config from another database config:
    
    development:
    	...
    
    production:
      development
    
    This stopped working when @tenderlove used
    his refactoring sword to slice the
    establish_connection logic on commit
    2a9a8ad
This page is out of date. Refresh to see the latest.
4 activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
View
@@ -17,7 +17,7 @@ def initialize(config, configurations)
end
def spec
- case config
+ case config
when nil
raise AdapterNotSpecified unless defined?(Rails.env)
resolve_string_connection Rails.env
@@ -36,7 +36,7 @@ def resolve_string_connection(spec) # :nodoc:
raise(AdapterNotSpecified, "#{spec} database is not configured") unless hash
- resolve_hash_connection hash
+ hash.is_a?(Hash) ? resolve_hash_connection(hash) : resolve_string_connection(hash)
end
def resolve_hash_connection(spec) # :nodoc:
13 activerecord/test/cases/connection_specification/resolver_test.rb
View
@@ -4,11 +4,18 @@ module ActiveRecord
class Base
class ConnectionSpecification
class ResolverTest < ActiveRecord::TestCase
- def resolve(spec)
- Resolver.new(spec, {}).spec.config
+
+ def resolve(spec)
+ @configurations = ActiveRecord::Base.configurations.merge({'arunit_alias' => 'arunit'})
+ Resolver.new(spec, @configurations).spec.config
end
- def test_url_host_no_db
+ def test_alias_host
+ spec = resolve 'arunit_alias'
+ assert_equal(@configurations['arunit'].symbolize_keys, spec)
+ end
+
+ def test_url_host_no_db
spec = resolve 'mysql://foo?encoding=utf8'
assert_equal({
:adapter => "mysql",
Something went wrong with that request. Please try again.