Skip to content

Commit

Permalink
Merge pull request #36 from hkim3162/additional_changes_to_prodder_ra…
Browse files Browse the repository at this point in the history
…ils_upgrade

change db config back to active record config
  • Loading branch information
rnubel authored Mar 1, 2023
2 parents 2178135 + f9c3351 commit 16ee170
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/prodder/prodder.rake
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace :db 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 = Rails.configuration.database_configuration[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'])}`
Expand All @@ -217,7 +217,7 @@ namespace :db do
task :seed => dependencies do
if File.exist?('db/seeds.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
config = Rails.configuration.database_configuration[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'])}`
Expand All @@ -232,7 +232,7 @@ namespace :db do
task :quality_check => dependencies do
if File.exist?('db/quality_checks.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
config = Rails.configuration.database_configuration[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'])}`
Expand All @@ -247,7 +247,7 @@ namespace :db do
task :permission => dependencies do
if File.exist?('db/permissions.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
config = Rails.configuration.database_configuration[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
Expand All @@ -268,7 +268,7 @@ namespace :db do
task :settings => dependencies do
if File.exist?('db/settings.sql')
as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do
config = Rails.configuration.database_configuration[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
Expand Down Expand Up @@ -362,19 +362,19 @@ namespace :db do

def as(user, opts = {}, &block)
if File.exist?('db/permissions.sql')
config, config_was = Rails.configuration.database_configuration.deep_dup.to_h, Rails.configuration.database_configuration.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) }
Rails.configuration.database_configuration = config
ActiveRecord::Base.configurations = config
end
else
puts "No permissions file (db/permissions.sql) found, running everything in context of user"
end
yield
ensure
Rails.configuration.database_configuration = config_was if config_was
ActiveRecord::Base.configurations = config_was if config_was
in_env.each { |env| ActiveRecord::Base.establish_connection(env.intern) } if in_env
end

Expand All @@ -393,5 +393,5 @@ end

# Yes, I really want migrations to run against the test DB.
Rake::Task['db:migrate'].actions.unshift(proc {
ActiveRecord::Base.establish_connection(Rails.configuration.database_configuration[(ENV['RAILS_ENV'] || Rails.env).to_sym])
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env].with_indifferent_access)
})
2 changes: 1 addition & 1 deletion lib/prodder/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Prodder
VERSION = "1.8.0"
VERSION = "1.8.1"
end

0 comments on commit 16ee170

Please sign in to comment.