Skip to content

chore: update upgrade scripts #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/check-shellscripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Check shell scripts

on:
push:
branches:
- develop
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -e SC2001 -e SC2002 -e SC2143
with:
scandir: './ansible/files/admin_api_scripts'
4 changes: 2 additions & 2 deletions ansible/files/admin_api_scripts/manage_readonly_mode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FROM role_comment;
EOF
)
RESULT=$(psql -h localhost -U supabase_admin -d postgres -At -c "$COMMAND")
echo -n $RESULT
echo -n "$RESULT"
}

case $SUBCOMMAND in
Expand All @@ -36,7 +36,7 @@ case $SUBCOMMAND in
;;
"set")
shift
set_mode $@
set_mode "$@"
;;
*)
echo "Error: '$SUBCOMMAND' is not a known subcommand."
Expand Down
30 changes: 12 additions & 18 deletions ansible/files/admin_api_scripts/pg_upgrade_complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
## The following commands copy custom PG configs and enable previously disabled
## extensions, containing regtypes referencing system OIDs.

# Extensions to be reenabled after pg_upgrade.
# Running an upgrade with these extensions enabled will result in errors due to
# them depending on regtypes referencing system OIDs. Thus they have been disabled
# beforehand.
EXTENSIONS_TO_REENABLE=(
"pg_graphql"
)

set -eEuo pipefail

run_sql() {
Expand All @@ -23,9 +15,9 @@ cleanup() {
UPGRADE_STATUS=${1:-"failed"}
EXIT_CODE=${?:-0}

echo "${UPGRADE_STATUS}" > /tmp/pg-upgrade-status
echo "$UPGRADE_STATUS" > /tmp/pg-upgrade-status

exit $EXIT_CODE
exit "$EXIT_CODE"
}

function complete_pg_upgrade {
Expand All @@ -36,37 +28,39 @@ function complete_pg_upgrade {

echo "running" > /tmp/pg-upgrade-status

echo "1. Mounting data disk"
mount -a -v

# copying custom configurations
echo "2. Copying custom configurations"
cp -R /data/conf/* /etc/postgresql-custom/
chown -R postgres:postgres /var/lib/postgresql/data
chown -R postgres:postgres /data/pgdata

echo "3. Starting postgresql"
service postgresql start

for EXTENSION in "${EXTENSIONS_TO_REENABLE[@]}"; do
run_sql -c "CREATE EXTENSION IF NOT EXISTS ${EXTENSION} CASCADE;"
done

echo "4. Running generated SQL files"
if [ -d /data/sql ]; then
for FILE in /data/sql/*.sql; do
if [ -f "$FILE" ]; then
run_sql -f $FILE
run_sql -f "$FILE"
fi
done
fi

sleep 5

echo "5. Restarting postgresql"
service postgresql restart

echo "6. Starting vacuum analyze"
start_vacuum_analyze

echo "Upgrade job completed"
}

function start_vacuum_analyze {
su -c 'vacuumdb --all --analyze-in-stages' -s $SHELL postgres
su -c 'vacuumdb --all --analyze-in-stages' -s "$SHELL" postgres
echo "Upgrade job completed"
cleanup "complete"
}

Expand Down
Loading