diff --git a/libraries/helpers.rb b/libraries/helpers.rb index b00337ec..6fd21369 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -23,12 +23,17 @@ module Cookbook module Helpers include Utils - def installed_postgresql_major_version + def installed_postgresql_package_logic pgsql_package = node['packages'].filter { |p| p.match?(/^postgresql-?(\d+)?$/) } + pgsql_package = pgsql_package.sort_by { |key, _values| key }.to_h raise 'Unable to determine installed PostgreSQL version' if nil_or_empty?(pgsql_package) - pgsql_package = pgsql_package.values.first + pgsql_package.values.first + end + + def installed_postgresql_major_version + pgsql_package = installed_postgresql_package_logic pgsql_package_version = pgsql_package.fetch('version').to_i pgsql_package_source = if pgsql_package.key?('release') pgsql_package.fetch('release').match?('PGDG') ? :repo : :os @@ -42,11 +47,7 @@ def installed_postgresql_major_version end def installed_postgresql_package_source - pgsql_package = node['packages'].filter { |p| p.match?(/^postgresql-?(\d+)?$/) } - - raise 'Unable to determine installed PostgreSQL version' if nil_or_empty?(pgsql_package) - - pgsql_package = pgsql_package.values.first + pgsql_package = installed_postgresql_package_logic pgsql_package_version = pgsql_package.fetch('version').to_i pgsql_package_source = if pgsql_package.key?('release') pgsql_package.fetch('release').match?('PGDG') ? :repo : :os