Skip to content

Commit 0983daa

Browse files
Deprecate config in dbconsole
This change deprecates config in dbconsole and updates usage in the dbconsole tests so that we can remove an accessor on the `configuration_hash`. Eventually we want to pass objects around everywhere instead of hashes. Callers can use `db_config` to access the hash if necessary. Co-authored-by: John Crepezzi <[email protected]>
1 parent 4500ebb commit 0983daa

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

railties/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Deprecate `Rails::DBConsole#config`
2+
3+
`Rails::DBConsole#config` is deprecated without replacement. Use `Rails::DBConsole.db_config.configuration_hash` instead.
4+
5+
*Eileen M. Uchitelle*, *John Crepezzi*
6+
17
* `Rails.application.config_for` merges shared configuration deeply.
28

39
```yaml

railties/lib/rails/commands/dbconsole/dbconsole_command.rb

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def initialize(options = {})
1616

1717
def start
1818
ENV["RAILS_ENV"] ||= @options[:environment] || environment
19+
config = db_config.configuration_hash
1920

2021
case db_config.adapter
2122
when /^(jdbc)?mysql/
@@ -92,6 +93,7 @@ def start
9293
def config
9394
db_config.configuration_hash
9495
end
96+
deprecate config: "please use db_config.configuration_hash"
9597

9698
def db_config
9799
return @db_config if defined?(@db_config)

railties/test/commands/dbconsole_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def test_config_with_db_config_only
3030
}
3131
}
3232
app_db_config(config_sample) do
33-
assert_equal config_sample["test"].symbolize_keys, Rails::DBConsole.new.config
33+
assert_equal config_sample["test"].symbolize_keys, Rails::DBConsole.new.db_config.configuration_hash
3434
end
3535
end
3636

3737
def test_config_with_no_db_config
3838
app_db_config(nil) do
3939
assert_raise(ActiveRecord::AdapterNotSpecified) {
40-
Rails::DBConsole.new.config
40+
Rails::DBConsole.new.db_config.configuration_hash
4141
}
4242
end
4343
end
@@ -56,7 +56,7 @@ def test_config_with_database_url_only
5656
}.sort
5757

5858
app_db_config(nil) do
59-
assert_equal expected, Rails::DBConsole.new.config.sort
59+
assert_equal expected, Rails::DBConsole.new.db_config.configuration_hash.sort
6060
end
6161
end
6262

@@ -76,7 +76,7 @@ def test_config_choose_database_url_if_exists
7676
}
7777
}
7878
app_db_config(sample_config) do
79-
assert_equal host, Rails::DBConsole.new.config[:host]
79+
assert_equal host, Rails::DBConsole.new.db_config.configuration_hash[:host]
8080
end
8181
end
8282

@@ -213,7 +213,7 @@ def test_primary_is_automatically_picked_with_3_level_configuration
213213
}
214214

215215
app_db_config(sample_config) do
216-
assert_equal "postgresql", Rails::DBConsole.new.config[:adapter]
216+
assert_equal "postgresql", Rails::DBConsole.new.db_config.configuration_hash[:adapter]
217217
end
218218
end
219219

0 commit comments

Comments
 (0)