From ab0d164e2118a18eef08d6e986605e229834dc03 Mon Sep 17 00:00:00 2001
From: Nicolas Dandrimont <nicolas@dandrimont.eu>
Date: Tue, 18 Mar 2025 11:52:22 +0100
Subject: [PATCH] Handle non-zero return codes for swh storage cassandra
 upgrade

---
 swh/templates/utils/backend-utils.yaml | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/swh/templates/utils/backend-utils.yaml b/swh/templates/utils/backend-utils.yaml
index 20bba299..1103ea75 100644
--- a/swh/templates/utils/backend-utils.yaml
+++ b/swh/templates/utils/backend-utils.yaml
@@ -362,7 +362,29 @@ data:
     [ ! -f "${CONFIG_CASSANDRA}" ] && \
         echo "Missing <${CONFIG_CASSANDRA}> file" && exit 1
 
-    swh storage --config-file=${CONFIG_CASSANDRA} cassandra upgrade
+    ret=0
+
+    swh storage --config-file=${CONFIG_CASSANDRA} cassandra list-migrations
+    swh storage --config-file=${CONFIG_CASSANDRA} cassandra upgrade || ret=$?
+
+    case "$ret" in
+        0)
+          # Migrations have succeeded
+          exit 0
+          ;;
+        3)
+          # No migrations to do
+          exit 0
+          ;;
+        5)
+          # Only optional migrations are left to do, we can start the RPC service
+          exit 0
+          ;;
+        *)
+          # Unknown exit code
+          exit $ret
+          ;;
+    esac
 
   extract-storage-postgresql-config-py: |
     import yaml
-- 
GitLab