Skip to content

Commit dd15fb6

Browse files
authored
feat(pg_upgrade): use self-hosted nix installer if available; move files out of /tmp (#1191)
1 parent 6ade943 commit dd15fb6

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,13 @@ function apply_auth_scheme_updates {
170170

171171
function start_vacuum_analyze {
172172
echo "complete" > /tmp/pg-upgrade-status
173-
if ! command -v nix &> /dev/null; then
174-
su -c 'vacuumdb --all --analyze-in-stages' -s "$SHELL" postgres
175-
else
176-
su -c '. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && vacuumdb --all --analyze-in-stages' -s "$SHELL" postgres
173+
174+
# shellcheck disable=SC1091
175+
if [ -f "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]; then
176+
# shellcheck disable=SC1091
177+
source "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
177178
fi
179+
vacuumdb --all --analyze-in-stages -U supabase_admin -h localhost -p 5432
178180
echo "Upgrade job completed"
179181
}
180182

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ PGBINOLD="/usr/lib/postgresql/bin"
4949
PGLIBOLD="/usr/lib/postgresql/lib"
5050

5151
PG_UPGRADE_BIN_DIR="/tmp/pg_upgrade_bin/$PGVERSION"
52+
NIX_INSTALLER_PATH="/tmp/persistent/nix-installer"
53+
NIX_INSTALLER_PACKAGE_PATH="$NIX_INSTALLER_PATH.tar.gz"
5254

5355
if [ -L "$PGBINOLD/pg_upgrade" ]; then
5456
BINARY_PATH=$(readlink -f "$PGBINOLD/pg_upgrade")
@@ -286,9 +288,18 @@ function initiate_upgrade {
286288
if ! command -v nix > /dev/null; then
287289
echo "1.1. Nix is not installed; installing."
288290

289-
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --no-confirm \
290-
--extra-conf "substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com" \
291-
--extra-conf "trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
291+
if [ -f "$NIX_INSTALLER_PACKAGE_PATH" ]; then
292+
echo "1.1.1. Installing Nix using the provided installer"
293+
tar -xzf "$NIX_INSTALLER_PACKAGE_PATH" -C /tmp/persistent/
294+
chmod +x "$NIX_INSTALLER_PATH"
295+
"$NIX_INSTALLER_PATH" install --no-confirm
296+
else
297+
echo "1.1.1. Installing Nix using the official installer"
298+
299+
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --no-confirm \
300+
--extra-conf "substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com" \
301+
--extra-conf "trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
302+
fi
292303
else
293304
echo "1.1. Nix is installed; moving on."
294305
fi

0 commit comments

Comments
 (0)