lib/prodder/prodder.rake in prodder-1.8.1 vs lib/prodder/prodder.rake in prodder-1.8.2
- old
+ new
@@ -167,11 +167,11 @@
else
environments = [Rails.env, "test"]
end
as("superuser", in: environments) do
ActiveRecord::Tasks::DatabaseTasks.create_current
- Rails.configuration.database_configuration.each do |env, config|
+ ActiveRecord::Base.configurations.to_h.each do |env, config|
if environments.include?(env) && config["migration_user"] && config['database']
set_psql_env config
`psql --no-psqlrc --command "ALTER DATABASE #{config['database']} OWNER TO #{config['migration_user']}" #{Shellwords.escape(config['database'])}`
end
end
@@ -180,11 +180,11 @@
namespace :create do
task :all => dependencies do
as("superuser") do
ActiveRecord::Tasks::DatabaseTasks.create_all
- Rails.configuration.database_configuration.each do |env, config|
+ ActiveRecord::Base.configurations.to_h.each do |env, config|
if config["migration_user"] && config['database']
set_psql_env config
`psql --no-psqlrc --command "ALTER DATABASE #{config['database']} OWNER TO #{config['migration_user']}" #{Shellwords.escape(config['database'])}`
end
end
@@ -360,22 +360,22 @@
end
end
def as(user, opts = {}, &block)
if File.exist?('db/permissions.sql')
- config, config_was = Rails.configuration.database_configuration, ActiveRecord::Base.configurations.deep_dup
- in_env = Array(opts[:in]) || config.keys
- if config.all? { |env, config_hash| in_env.include?(env) ? config_hash[user] : true }
- disconnect
- config.each { |env, config_hash| config_hash["username"] = config_hash[user] if in_env.include?(env) }
- ActiveRecord::Base.configurations = config
+ original_config = ActiveRecord::Base.configurations.deep_dup
+ in_env = Array(opts[:in]) || ActiveRecord::Base.configurations.deep_dup.to_h.keys
+ disconnect
+ in_env.each do |env|
+ config = ActiveRecord::Base.configurations.find_db_config(env)
+ config["username"] = config[user]
end
else
puts "No permissions file (db/permissions.sql) found, running everything in context of user"
end
yield
ensure
- ActiveRecord::Base.configurations = config_was if config_was
+ ActiveRecord::Base.configurations = original_config if original_config
in_env.each { |env| ActiveRecord::Base.establish_connection(env.intern) } if in_env
end
def disconnect
if ActiveRecord::Base.connection_pool && ActiveRecord::Base.connection_pool.connections.size > 0