Skip to content

Commit 69346f0

Browse files
committed
feat: Add the check to make the downgrade not possible
1 parent d21e985 commit 69346f0

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ The complete list of available properties can be found in the [spec](jobs/postgr
7676

7777
Property | Description
7878
-------- | -------------
79-
databases.version | Define the used PostgreSQL major version. Default: 15
79+
databases.version | Define the used PostgreSQL major version. Default: 16
8080
databases.port | The database port. Default: 5432
8181
databases.databases | A list of databases and associated properties to create when Postgres starts
8282
databases.databases[n].name | Database name

jobs/postgres/spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ provides:
4646
properties:
4747
databases.version:
4848
description: "The database version e.g. 11, 13, 15 or 16"
49-
default: "16"
49+
default: 16
5050
databases.port:
5151
description: "The database port"
5252
default: 5432

jobs/postgres/templates/utils.sh.erb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ function is_major() {
6868
[ "${pgversion_current%.*}" != "${pgversion_upgrade_from%.*}" ]
6969
}
7070

71+
function check_postgresql_versions(){
72+
if [[ $(echo -e "$pgversion_upgrade_from\n$pgversion_current" | sort --version-sort | head --lines=1) != $pgversion_upgrade_from ]]; then
73+
echo "The downgrade of the database instance is not supported."
74+
exit 1
75+
fi
76+
}
77+
7178
function init_data_dir(){
7279
if [ ! -f "${DATA_DIR}/postgresql.conf" ]; then
7380
# initdb creates data directories
@@ -77,7 +84,7 @@ function init_data_dir(){
7784
}
7885

7986
function run_major_upgrade(){
80-
if is_major; then
87+
if is_major && check_postgresql_versions; then
8188
rm -rf ${DATA_DIR_PREVIOUS}
8289
echo "Running a PostgreSQL major upgrade from ${pgversion_upgrade_from} to ${pgversion_current}"
8390
touch "$POSTGRES_UPGRADE_LOCK"
@@ -105,7 +112,7 @@ EOF
105112
fi
106113
}
107114
function run_minor_upgrade(){
108-
if ! is_major; then
115+
if ! is_major && check_postgresql_versions; then
109116
rm -rf ${DATA_DIR_PREVIOUS}
110117
echo "Running a PostgreSQL minor upgrade from ${pgversion_upgrade_from} to ${pgversion_current}"
111118
<% if p("databases.skip_data_copy_in_minor") %>

test/test_major_or_minor_version.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ pgversion_current=$2
55
# From postgres-x.y.z, it's major if x and y are not the same
66
# in $pgversion_current and $pgversion_upgrade_from
77

8+
function check_postgresql_versions(){
9+
if [[ $(echo -e "$pgversion_upgrade_from\n$pgversion_current" | sort --version-sort | head --lines=1) != $pgversion_upgrade_from ]]; then
10+
echo "The downgrade of the database instance is not supported."
11+
exit 1
12+
fi
13+
}
14+
815
function is_major() {
916
[ "${pgversion_current%.*}" != "${pgversion_upgrade_from%.*}" ]
1017
}
11-
if is_major; then
18+
19+
if is_major && check_postgresql_versions; then
1220
echo is major
1321
else
1422
echo is minor

0 commit comments

Comments
 (0)