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

Properly support DATABASE_URL #112

Merged
merged 1 commit into from
Apr 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/standalone_migrations/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ def on(config_key)
class Configurator
def self.load_configurations
@standalone_configs ||= Configurator.new.config
if url = ENV['DATABASE_URL']
@environments_config = {url: url}
else
@environments_config ||= YAML.load(ERB.new(File.read(@standalone_configs)).result).with_indifferent_access
end
@env_config ||= Rails.application.config.database_configuration
ActiveRecord::Base.configurations = @env_config
@env_config
end

def self.environments_config
Expand All @@ -43,6 +41,9 @@ def initialize(options = {})
}
@options = load_from_file(defaults.dup) || defaults.merge(options)
ENV['SCHEMA'] = ENV['SCHEMA'] || File.expand_path(schema)

Rails.application.config.root = Pathname.pwd
Rails.application.config.paths["config/database"] = config
end

def config
Expand All @@ -66,7 +67,7 @@ def config_for_all
end

def config_for(environment)
config_for_all[environment]
config_for_all[environment.to_s]
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/standalone_migrations/tasks/connection.rake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require File.expand_path("../../../standalone_migrations", __FILE__)
namespace :standalone do
task :connection do
configurator = StandaloneMigrations::Configurator.new
ActiveRecord::Base.establish_connection configurator.config_for(Rails.env)
StandaloneMigrations::Configurator.load_configurations
ActiveRecord::Base.establish_connection
StandaloneMigrations.run_on_load_callbacks
end
end
2 changes: 1 addition & 1 deletion spec/standalone_migrations/configurator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module StandaloneMigrations

it "load the yaml with environment configurations" do
config = Configurator.new.config_for(:development)
config[:database].should == "db/development.sql"
config["database"].should == "db/development.sql"
end

it "allow access the original configuration hash (for all environments)" do
Expand Down