Skip to content

Commit

Permalink
Refs #37678 - Update evr extension ownership after postgresql upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Aug 7, 2024
1 parent de26c75 commit 2db4db4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions hooks/boot/01-kafo-hook-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def execute!(command, do_say = true, do_log = true)
log_and_say(:error, "#{command} failed! Check the output for error!", do_say, do_log)
exit 1
end
stdout_stderr
end

def execute_as!(user, command, do_say = true, do_log = true)
Expand Down
5 changes: 5 additions & 0 deletions hooks/boot/06-postgresql-upgrade-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def postgresql_upgrade(new_version)

execute_as!('postgres', 'vacuumdb --all --analyze-in-stages', false, true)

if new_version.to_i == 13
logger.notice("Updating ownership of the evr extension if upgrading to postgres version 13")
execute!("runuser -l postgres -c \"psql -d foreman -c \\\"UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='foreman') WHERE extname='evr';\\\"\"", false, true)
end

logger.notice("Upgrade to PostgreSQL #{new_version} completed")
end

Expand Down
5 changes: 5 additions & 0 deletions hooks/pre/35-change-evr-extension-ownership.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
logger.notice("Updating ownership of the evr extension if it is enabled")
result = execute!("runuser -l postgres -c \"psql -d foreman -c \\\"SELECT 1 from pg_extension WHERE extname='evr';\\\"\"", false, true)
unless (result.include?('(0 rows)'))
execute!("runuser -l postgres -c \"psql -d foreman -c \\\"UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='foreman') WHERE extname='evr';\\\"\"", false, true)
end

0 comments on commit 2db4db4

Please sign in to comment.