lib/prodder/prodder.rake in prodder-1.7.7 vs lib/prodder/prodder.rake in prodder-1.8.1
- old
+ new
@@ -167,11 +167,11 @@
else
environments = [Rails.env, "test"]
end
as("superuser", in: environments) do
ActiveRecord::Tasks::DatabaseTasks.create_current
- ActiveRecord::Base.configurations.each do |env, config|
+ Rails.configuration.database_configuration.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
- ActiveRecord::Base.configurations.each do |env, config|
+ Rails.configuration.database_configuration.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
@@ -202,11 +202,11 @@
namespace :structure do
desc "Load db/structure.sql into the current environment's database"
task :load => dependencies do
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
- config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access
set_psql_env config
puts "Loading db/structure.sql into database '#{config['database']}'"
`psql --no-psqlrc -f db/structure.sql #{Shellwords.escape(config['database'])}`
raise 'Error loading db/structure.sql' if $?.exitstatus != 0
end
@@ -215,11 +215,11 @@
desc "Load initial seeds from db/seeds.sql"
task :seed => dependencies do
if File.exist?('db/seeds.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
- config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access
set_psql_env config
puts "Loading db/seeds.sql into database '#{config['database']}'"
`psql --no-psqlrc -f db/seeds.sql #{Shellwords.escape(config['database'])}`
raise 'Error loading db/seeds.sql' if $?.exitstatus != 0
end
@@ -230,11 +230,11 @@
desc "Load quality_checks (indexes, triggers, foreign keys) from db/quality_checks.sql"
task :quality_check => dependencies do
if File.exist?('db/quality_checks.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
- config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access
set_psql_env config
puts "Loading db/quality_checks.sql into database '#{config['database']}'"
`psql --no-psqlrc -f db/quality_checks.sql #{Shellwords.escape(config['database'])}`
raise 'Error loading db/quality_checks.sql' if $?.exitstatus != 0
end
@@ -245,11 +245,11 @@
desc "Load permissions (DB object level access control, group role memberships) from db/permissions.sql"
task :permission => dependencies do
if File.exist?('db/permissions.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
- config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access
set_psql_env config
puts "Loading db/permissions.sql into database '#{config['database']}'"
result = ActiveRecord::Base.connection.execute(<<-SQL).first
select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper
SQL
@@ -266,11 +266,11 @@
desc "Load database settings"
task :settings => dependencies do
if File.exist?('db/settings.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
- config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]
+ config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access
set_psql_env config
puts "Loading db/settings.sql into database '#{config['database']}'"
result = ActiveRecord::Base.connection.execute(<<-SQL).first
select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper
SQL
@@ -360,12 +360,11 @@
end
end
def as(user, opts = {}, &block)
if File.exist?('db/permissions.sql')
- # `ActiveRecord::Base.configurations` in Rails 6 now returns an object instead of a hash
- config, config_was = ActiveRecord::Base.configurations.deep_dup.to_h, ActiveRecord::Base.configurations.deep_dup
+ 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
@@ -392,7 +391,7 @@
task :prepare => [ 'db:test:prepare' ]
end
# Yes, I really want migrations to run against the test DB.
Rake::Task['db:migrate'].actions.unshift(proc {
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env])
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access)
})