From 4e317f804cf52a5b5b8ef9c77b2e101c45455deb Mon Sep 17 00:00:00 2001 From: Wade Winningham Date: Mon, 10 Jun 2024 05:56:07 -0700 Subject: [PATCH] Allow for new database.yml configurations with roles (#272) 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. --- packages/data_taster/lib/data_taster/flavors.rb | 2 +- packages/data_taster/lib/data_taster/helper.rb | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/data_taster/lib/data_taster/flavors.rb b/packages/data_taster/lib/data_taster/flavors.rb index 2830918a..e6686779 100644 --- a/packages/data_taster/lib/data_taster/flavors.rb +++ b/packages/data_taster/lib/data_taster/flavors.rb @@ -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 diff --git a/packages/data_taster/lib/data_taster/helper.rb b/packages/data_taster/lib/data_taster/helper.rb index dbaf8a59..daea2fdd 100644 --- a/packages/data_taster/lib/data_taster/helper.rb +++ b/packages/data_taster/lib/data_taster/helper.rb @@ -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)