Skip to content

Commit

Permalink
ConnectionAdapter with check_version overriding
Browse files Browse the repository at this point in the history
New OvirtPostgreSQLAdapter that extends the default one adding
a check_version method to override restrictions imposed by the
manageiq postgresql_required_versions initializer.
This modification, with the update of the initializer mentioned
above should solve:

https://bugzilla.redhat.com/show_bug.cgi?id=1734770
  • Loading branch information
gekorob committed Aug 2, 2019
1 parent 1e380c4 commit 66eda04
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 30 additions & 0 deletions lib/active_record/connection_adapters/ovirt_postgresql_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module ActiveRecord
module ConnectionHandling # :nodoc:
def ovirt_postgresql_connection(config)
conn_params = config.symbolize_keys

conn_params.delete_if { |_, v| v.nil? }

conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]

valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
conn_params.slice!(*valid_conn_param_keys)

ConnectionAdapters::OvirtPostgreSQLAdapter.new(nil, logger, conn_params, config)
end
end

module ConnectionAdapters
class OvirtPostgreSQLAdapter < PostgreSQLAdapter
ADAPTER_NAME = "OvirtPostgreSQL"

def check_version
msg = "The version of PostgreSQL (#{postgresql_version}) is too old (9.2+ required)"
if postgresql_version < 90200
raise msg
end
end
end
end
end
5 changes: 4 additions & 1 deletion lib/ovirt_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def self.connect(opts)
opts ||= {}
opts[:port] ||= 5432
opts[:database] ||= DEFAULT_HISTORY_DATABASE_NAME
opts[:adapter] = 'postgresql'
opts[:adapter] = begin
require "active_record/connection_adapters/ovirt_postgresql_adapter"
'ovirt_postgresql'
end

# Don't allow accidental connections to localhost. A blank host will
# connect to localhost, so don't allow that at all.
Expand Down

0 comments on commit 66eda04

Please sign in to comment.