Skip to content

Commit

Permalink
Initial code to automatically upgrade PG database extensions
Browse files Browse the repository at this point in the history
Completely untested. ;)
  • Loading branch information
justinclift committed Oct 10, 2024
1 parent e08fc14 commit d844878
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pgautoupgrade-postupgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,40 @@ echo "-------------------------------"
echo "End of reindexing the databases"
echo "-------------------------------"

# Update the extensions
echo "-----------------------"
echo "Updating the extensions"
echo "-----------------------"

# For each database, update its extensions
for DATABASE in ${DB_LIST}; do
echo "-----------------------------------------"
echo "Starting extension update for ${DATABASE}"
echo "-----------------------------------------"

EXTENSION_LIST=$(echo 'SELECT name FROM pg_catalog.pg_available_extensions WHERE default_version <> installed_version' | psql -t --csv "${DATABASE}")

for EXTENSION in ${EXTENSION_LIST}; do
echo "-------------------------------"
echo "Updating extension ${EXTENSION}"
echo "-------------------------------"

echo 'ALTER EXTENSION foobar UPDATE' | psql -t --csv "${DATABASE}"

echo "----------------------------------------"
echo "Finished updating extension ${EXTENSION}"
echo "----------------------------------------"
done

echo "-----------------------------------------"
echo "Finished extension update for ${DATABASE}"
echo "-----------------------------------------"
done

echo "--------------------------------"
echo "Finished updating the extensions"
echo "--------------------------------"

# If "one shot" mode was requested, then shut down PostgreSQL
if [ "x${PGAUTO_ONESHOT}" = "xyes" ]; then
echo "****************************************************************************************************"
Expand Down

0 comments on commit d844878

Please sign in to comment.