-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37717 - Update evr extension ownership to foreman
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# 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") | ||
else | ||
start_services(['postgresql']) | ||
end | ||
|
||
database = param_value('foreman', 'db_database') || 'foreman' | ||
username = param_value('foreman', 'db_username') || 'foreman' | ||
|
||
if local_db_exists?(database) | ||
sql = "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_preformatted_as('postgres', "psql -d #{database} -c \"#{sql}\"", false, true) | ||
end | ||
else | ||
logger.debug("The foreman database does not exist.") | ||
end | ||
end |