Skip to content

Commit

Permalink
Allow for new database.yml configurations with roles (#272)
Browse files Browse the repository at this point in the history
Newer Rails applications may be using a [configuration for multiple
databases](https://guides.rubyonrails.org/active_record_multiple_databases.html).

By default, Rails will look for`primary` named connection details and
use those with multiple db setup. The changes in this PR will look for
and use the `primary` settings if the key exists, otherwise, it will
assume it's normal, single db, database setttings which would be
compatible with previous versions of Rails.
  • Loading branch information
wadewinningham authored Jun 10, 2024
1 parent d54f469 commit 4e317f8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/data_taster/lib/data_taster/flavors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def recent_ids(table_name, col_name)
end

def source_db
@source_db ||= db_config["database"]
@source_db ||= db_config[:database]
end
end
end
6 changes: 1 addition & 5 deletions packages/data_taster/lib/data_taster/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ def sanitize_command(command, params = nil)
sanitized_command
end

def db_yml
@db_yml ||= YAML.safe_load(ERB.new(Rails.root.join("config", "database.yml").read).result, aliases: true)
end

def db_config
@db_config ||= db_yml[Rails.env]
ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: "primary").configuration_hash
end

def logg(message)
Expand Down

0 comments on commit 4e317f8

Please sign in to comment.