Skip to content

Commit 231844a

Browse files
committed
Refactor how we check if PostgreSQL should be prepared for migration
Having the same check in two places is error prone to not updating both places with changes. Exactly as it happened recently in 7c515c8. Doing the check once and storing the result is better and will also make it easier to change the check to something more complex doing decisions on version differences and not hardcoded values.
1 parent f55738d commit 231844a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packaging/common/cfengine-hub/preinstall.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ if is_upgrade; then
1515
fi
1616
fi
1717

18-
BACKUP_DIR=$PREFIX/backup-before-postgres11-migration
19-
2018
# If upgrading from a version below 3.13 that has PostgreSQL, and the data dir exists.
2119
if is_upgrade && egrep '^3\.([6-9]|1[012])\.' "$PREFIX/UPGRADED_FROM.txt" >/dev/null && [ -d "$PREFIX/state/pg/data" ]; then
20+
alias migrating_postgres='true'
21+
else
22+
alias migrating_postgres='false'
23+
fi
24+
25+
BACKUP_DIR=$PREFIX/backup-before-postgres11-migration
26+
27+
if migrating_postgres; then
2228
if [ -d "$BACKUP_DIR/data" ]; then
2329
cf_console echo "Old backup in $BACKUP_DIR already exists. Please remove before attempting upgrade."
2430
exit 1
@@ -125,7 +131,7 @@ if is_upgrade; then
125131
fi
126132
fi
127133

128-
if is_upgrade && egrep '^3\.([6-9]|1[01])\.' "$PREFIX/UPGRADED_FROM.txt" >/dev/null && [ -d "$PREFIX/state/pg/data" ]; then
134+
if migrating_postgres; then
129135
cf_console echo "Moving old data and copying old binaries to $BACKUP_DIR"
130136
# Now that PostgreSQL is shut down, move the old data out of the way.
131137
mkdir -p "$BACKUP_DIR/lib"

0 commit comments

Comments
 (0)