Skip to content

Commit 697bf58

Browse files
authored
chore: update upgrade scripts (#533)
* chore: update upgrade scripts to be compatible with older instances; refactoring; fixes * chore: better handling of updated package default files * chore: add shellcheck
1 parent 83af3de commit 697bf58

File tree

5 files changed

+205
-81
lines changed

5 files changed

+205
-81
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Check shell scripts
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Run ShellCheck
16+
uses: ludeeus/action-shellcheck@master
17+
env:
18+
SHELLCHECK_OPTS: -e SC2001 -e SC2002 -e SC2143
19+
with:
20+
scandir: './ansible/files/admin_api_scripts'

ansible/files/admin_api_scripts/manage_readonly_mode.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ FROM role_comment;
2727
EOF
2828
)
2929
RESULT=$(psql -h localhost -U supabase_admin -d postgres -At -c "$COMMAND")
30-
echo -n $RESULT
30+
echo -n "$RESULT"
3131
}
3232

3333
case $SUBCOMMAND in
@@ -36,7 +36,7 @@ case $SUBCOMMAND in
3636
;;
3737
"set")
3838
shift
39-
set_mode $@
39+
set_mode "$@"
4040
;;
4141
*)
4242
echo "Error: '$SUBCOMMAND' is not a known subcommand."

ansible/files/admin_api_scripts/pg_upgrade_complete.sh

+12-18
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@
55
## The following commands copy custom PG configs and enable previously disabled
66
## extensions, containing regtypes referencing system OIDs.
77

8-
# Extensions to be reenabled after pg_upgrade.
9-
# Running an upgrade with these extensions enabled will result in errors due to
10-
# them depending on regtypes referencing system OIDs. Thus they have been disabled
11-
# beforehand.
12-
EXTENSIONS_TO_REENABLE=(
13-
"pg_graphql"
14-
)
15-
168
set -eEuo pipefail
179

1810
run_sql() {
@@ -23,9 +15,9 @@ cleanup() {
2315
UPGRADE_STATUS=${1:-"failed"}
2416
EXIT_CODE=${?:-0}
2517

26-
echo "${UPGRADE_STATUS}" > /tmp/pg-upgrade-status
18+
echo "$UPGRADE_STATUS" > /tmp/pg-upgrade-status
2719

28-
exit $EXIT_CODE
20+
exit "$EXIT_CODE"
2921
}
3022

3123
function complete_pg_upgrade {
@@ -36,37 +28,39 @@ function complete_pg_upgrade {
3628

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

31+
echo "1. Mounting data disk"
3932
mount -a -v
4033

4134
# copying custom configurations
35+
echo "2. Copying custom configurations"
4236
cp -R /data/conf/* /etc/postgresql-custom/
4337
chown -R postgres:postgres /var/lib/postgresql/data
4438
chown -R postgres:postgres /data/pgdata
4539

40+
echo "3. Starting postgresql"
4641
service postgresql start
4742

48-
for EXTENSION in "${EXTENSIONS_TO_REENABLE[@]}"; do
49-
run_sql -c "CREATE EXTENSION IF NOT EXISTS ${EXTENSION} CASCADE;"
50-
done
51-
43+
echo "4. Running generated SQL files"
5244
if [ -d /data/sql ]; then
5345
for FILE in /data/sql/*.sql; do
5446
if [ -f "$FILE" ]; then
55-
run_sql -f $FILE
47+
run_sql -f "$FILE"
5648
fi
5749
done
5850
fi
5951

6052
sleep 5
53+
54+
echo "5. Restarting postgresql"
6155
service postgresql restart
6256

57+
echo "6. Starting vacuum analyze"
6358
start_vacuum_analyze
64-
65-
echo "Upgrade job completed"
6659
}
6760

6861
function start_vacuum_analyze {
69-
su -c 'vacuumdb --all --analyze-in-stages' -s $SHELL postgres
62+
su -c 'vacuumdb --all --analyze-in-stages' -s "$SHELL" postgres
63+
echo "Upgrade job completed"
7064
cleanup "complete"
7165
}
7266

0 commit comments

Comments
 (0)