From 25feabd112b8729f8835c05cb33297f8fbd9a0b5 Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Tue, 6 Aug 2024 13:01:43 -0400 Subject: [PATCH] Fixes #37717 - Update evr extension ownership to foreman --- .../pre/35-change-evr-extension-ownership.rb | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 hooks/pre/35-change-evr-extension-ownership.rb diff --git a/hooks/pre/35-change-evr-extension-ownership.rb b/hooks/pre/35-change-evr-extension-ownership.rb new file mode 100644 index 00000000..39161ac6 --- /dev/null +++ b/hooks/pre/35-change-evr-extension-ownership.rb @@ -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