Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove hard coded references to Active Record in railties

  • Loading branch information...
commit dd5a80dc3da794f9296ec199c492a398589257a0 1 parent c09f934
@josevalim josevalim authored
View
4 activerecord/lib/active_record/connection_adapters/connection_specification.rb
@@ -38,7 +38,7 @@ def spec
private
def resolve_string_connection(spec) # :nodoc:
hash = configurations.fetch(spec) do |k|
- self.class.connection_url_to_hash(k)
+ connection_url_to_hash(k)
end
raise(AdapterNotSpecified, "#{spec} database is not configured") unless hash
@@ -65,7 +65,7 @@ def resolve_hash_connection(spec) # :nodoc:
ConnectionSpecification.new(spec, adapter_method)
end
- def self.connection_url_to_hash(url) # :nodoc:
+ def connection_url_to_hash(url) # :nodoc:
config = URI.parse url
adapter = config.scheme
adapter = "postgresql" if adapter == "postgres"
View
2  activerecord/lib/active_record/railtie.rb
@@ -152,7 +152,7 @@ class Railtie < Rails::Railtie # :nodoc:
# and then establishes the connection.
initializer "active_record.initialize_database" do |app|
ActiveSupport.on_load(:active_record) do
- self.configurations = app.config.database_configuration
+ self.configurations = app.config.database_configuration || {}
establish_connection
end
end
View
2  activerecord/lib/active_record/railties/databases.rake
@@ -2,7 +2,7 @@ require 'active_record'
db_namespace = namespace :db do
task :load_config do
- ActiveRecord::Base.configurations = Rails.application.config.database_configuration
+ ActiveRecord::Base.configurations = Rails.application.config.database_configuration || {}
ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH)
View
13 railties/lib/rails/application/configuration.rb
@@ -98,14 +98,15 @@ def threadsafe!
end
# Loads and returns the configuration of the database.
- # First, looks at If ENV['DATABASE_URL'] if it's not present it uses the #paths["config/database"]
- # The contents of the file are processed via ERB before being sent through YAML::load.
def database_configuration
- if ENV['DATABASE_URL']
- {Rails.env => ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.connection_url_to_hash(ENV['DATABASE_URL']).stringify_keys}
+ yaml = paths["config/database"].first
+ if File.exists?(yaml)
+ require "erb"
+ YAML.load ERB.new(IO.read(yaml)).result
+ elsif ENV['DATABASE_URL']
+ nil
@fdr
fdr added a note

Surely this is not what is intended. If there is no configuration that otherwise specifies the database configuration, should it not load it from DATABASE_URL? Otherwise this check merely suppresses the subsequent error.

Yup. That seems to cause this bug: heroku/heroku-buildpack-ruby#93

@rafaelfranca Owner

Please guys, open a pull request

@rafaelfranca in fact, it can be solved from the buildpack side. If we do that, then, it won't have any hard-reference to ActiveRecord anymore on the Rails side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
else
- require 'erb'
- YAML.load ERB.new(IO.read(paths["config/database"].first)).result
+ raise "Could not load database configuration. No such file - #{yaml}"
end
rescue Psych::SyntaxError => e
raise "YAML syntax error occurred while parsing #{paths["config/database"].first}. " \
View
13 railties/test/application/rake/dbs_test.rb
@@ -166,19 +166,6 @@ def db_test_load_structure
require "#{app_path}/config/environment"
db_test_load_structure
end
-
- test 'db:test:load_structure with database_url' do
@josevalim Owner

This test was removed because it was broken. It was passing by accident and not testing the feature described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- old_rails_env = ENV["RAILS_ENV"]
- ENV["RAILS_ENV"] = 'test'
-
- begin
- require "#{app_path}/config/environment"
- set_database_url
- db_test_load_structure
- ensure
- ENV["RAILS_ENV"] = old_rails_env
- end
- end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.