Skip to content

Commit

Permalink
Fixes #37717 - Update evr extension ownership to foreman
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Dec 2, 2024
1 parent 349e482 commit 25feabd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions hooks/pre/35-change-evr-extension-ownership.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# In Katello 4.16, the 'evr' extension is removed from PostgreSQL and integrated into the Katello database via a migration.
# This hook ensures the 'evr' extension's ownership is transferred to the 'foreman' user so migrations can act on it.

if (local_foreman_db? || devel_scenario?) && execute("rpm -q postgresql-evr", false, false)
if app_value(:noop)
logger.debug("Would start postgresql service") if app_value(:noop)
else
start_services(['postgresql'])
end

# Update the ownership of the evr extension
database = param_value('foreman', 'db_database') || 'foreman'
username = param_value('foreman', 'db_username') || 'foreman'
sql = "psql -d '#{database}' -c \\\"UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='#{username}') WHERE extname='evr';\\\""
if app_value(:noop)
logger.debug("Would execute: #{sql} to update ownership of the evr extension")
else
logger.debug("Updating ownership of the evr extension")
execute_as!('postgres', sql, false, true)
end
end

0 comments on commit 25feabd

Please sign in to comment.