Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #28943 - pre-upgrade check to validate external DB version #322

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions definitions/checks/foreman/validate_external_db_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Checks
module Foreman
class ValidateExternalDbVersion < ForemanMaintain::Check
metadata do
description 'Make sure server is running on required database version'
tags :pre_upgrade
label :validate_external_db_version
confine do
feature(:foreman_database) && !feature(:foreman_database).local? &&
!check_min_version('foreman', '2.0')
end
end

def run
current_db_version = feature(:foreman_database).db_version
fail!(db_upgrade_message(current_db_version)) if current_db_version.major < 12
end

def db_upgrade_message(db_version)
product_name = feature(:instance).product_name

"\n\n*** ERROR: Server is running on PostgreSQL #{db_version} database.\n"\
"*** Newer version of #{product_name} supports only PostgreSQL version 12.\n"\
"*** Before proceeding further, you must upgrade database to PostgreSQL 12.\n"
end
end
end
end
11 changes: 11 additions & 0 deletions lib/foreman_maintain/concerns/base_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ def dropdb(config = configuration)
end
end

def db_version(config = configuration)
if ping(config)
# Note - t removes headers, -A removes alignment whitespace
server_version_cmd = psql_command(config) + ' -c "SHOW server_version" -t -A'
version_string = execute!(server_version_cmd, :hidden_patterns => [config['password']])
version(version_string)
else
raise_service_error
end
end

private

def base_command(config, command = 'psql')
Expand Down