Skip to content

Commit 8213c22

Browse files
authored
Merge pull request rails#54959 from flavorjones/flavorjones/run-hook-for-database-configurations
Add a load hook for `ActiveRecord::DatabaseConfigurations`
2 parents 9171072 + 3f0d13d commit 8213c22

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Add a load hook `active_record_database_configurations` for `ActiveRecord::DatabaseConfigurations`
2+
3+
*Mike Dalessio*
4+
15
* Use `TRUE` and `FALSE` for SQLite queries with boolean columns.
26

37
*Hartley McGuire*

activerecord/lib/active_record/database_configurations.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ class InvalidConfigurationError < StandardError; end
3636
# to respond to `sharded?`. To implement this define the following in an
3737
# initializer:
3838
#
39-
# ActiveRecord::DatabaseConfigurations.register_db_config_handler do |env_name, name, url, config|
40-
# next unless config.key?(:vitess)
41-
# VitessConfig.new(env_name, name, config)
39+
# ActiveSupport.on_load(:active_record_database_configurations) do
40+
# ActiveRecord::DatabaseConfigurations.register_db_config_handler do |env_name, name, url, config|
41+
# next unless config.key?(:vitess)
42+
# VitessConfig.new(env_name, name, config)
43+
# end
4244
# end
4345
#
4446
# Note: applications must handle the condition in which custom config should be
@@ -306,4 +308,6 @@ def environment_value_for(name)
306308
url
307309
end
308310
end
311+
312+
ActiveSupport.run_load_hooks(:active_record_database_configurations, DatabaseConfigurations)
309313
end

guides/source/configuring.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3820,6 +3820,7 @@ These are the load hooks you can use in your own code. To hook into the initiali
38203820
| `ActiveModel::Model` | `active_model` |
38213821
| `ActiveModel::Translation` | `active_model_translation` |
38223822
| `ActiveRecord::Base` | `active_record` |
3823+
| `ActiveRecord::DatabaseConfigurations` | `active_record_database_configurations` |
38233824
| `ActiveRecord::Encryption` | `active_record_encryption` |
38243825
| `ActiveRecord::TestFixtures` | `active_record_fixtures` |
38253826
| `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter` | `active_record_postgresqladapter` |

0 commit comments

Comments
 (0)