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

change db config back to active record config #36

Merged
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
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