Skip to content

Commit

Permalink
Fixed deprecation warnings with Active Record 7
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Dec 7, 2021
1 parent ef740b7 commit 9b03508
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2.8.2 (unreleased)

- Fixed sorting by name on space page when historical space stats are not enabled
- Fixed deprecation warnings with Active Record 7

## 2.8.1 (2021-03-25)

Expand Down
8 changes: 7 additions & 1 deletion lib/pghero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def config
databases = {}

if !ENV["PGHERO_DATABASE_URL"] && spec_supported?
ActiveRecord::Base.configurations.configs_for(env_name: env, include_replicas: true).each do |db|
ActiveRecord::Base.configurations.configs_for(env_name: env, include_replicas_key => true).each do |db|
databases[db.send(spec_name_key)] = {"spec" => db.send(spec_name_key)}
end
end
Expand Down Expand Up @@ -223,6 +223,12 @@ def spec_name_key
ActiveRecord::VERSION::STRING.to_f >= 6.1 ? :name : :spec_name
end

# private
# Rails 7.0 deprecate `include_replicas` and use `include_hidden`
def include_replicas_key
ActiveRecord::VERSION::MAJOR >= 7 ? :include_hidden : :include_replicas
end

private

def each_database
Expand Down
2 changes: 1 addition & 1 deletion lib/pghero/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def build_connection_model
# resolve spec
if !url && config["spec"]
raise Error, "Spec requires Rails 6+" unless PgHero.spec_supported?
config_options = {env_name: PgHero.env, PgHero.spec_name_key => config["spec"], include_replicas: true}
config_options = {env_name: PgHero.env, PgHero.spec_name_key => config["spec"], PgHero.include_replicas_key => true}
resolved = ActiveRecord::Base.configurations.configs_for(**config_options)
raise Error, "Spec not found: #{config["spec"]}" unless resolved
url = ActiveRecord::VERSION::STRING.to_f >= 6.1 ? resolved.configuration_hash : resolved.config
Expand Down

0 comments on commit 9b03508

Please sign in to comment.