From 59fc39620d67610176e607eaea1d4747757d101a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Fri, 16 Jan 2026 14:19:51 +0100 Subject: [PATCH] [IMP] improves the way postgres container is detected --- upgrade.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/upgrade.sh b/upgrade.sh index cedfd04..4d97e19 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -17,8 +17,21 @@ export FINALE_DB_NAME="ou${FINAL_VERSION}" # Define finale odoo service name FINALE_SERVICE_NAME="${FINALE_DB_NAME}" -# Service postgres name -export POSTGRES_SERVICE_NAME="lokavaluto_postgres_1" +# Service postgres name (dynamically retrieved from running containers) +POSTGRES_CONTAINERS=$(docker ps --format '{{.Names}}' | grep postgres) +POSTGRES_COUNT=$(echo "$POSTGRES_CONTAINERS" | grep -c .) + +if [ "$POSTGRES_COUNT" -eq 0 ]; then + echo "ERROR: No running PostgreSQL container found. Please start a PostgreSQL container and try again." >&2 + exit 1 +elif [ "$POSTGRES_COUNT" -gt 1 ]; then + echo "ERROR: Multiple PostgreSQL containers found:" >&2 + echo "$POSTGRES_CONTAINERS" >&2 + echo "Please ensure only one PostgreSQL container is running." >&2 + exit 1 +fi + +export POSTGRES_SERVICE_NAME="$POSTGRES_CONTAINERS" ############################################# # DISPLAYS ALL INPUTS PARAMETERS @@ -94,14 +107,6 @@ export -f exec_python_script_in_odoo_shell echo " ==== CHECKS ALL NEEDED COMPONENTS ARE AVAILABLE ====" -# Check POSTGRES container is running -if ! docker ps | grep -q "$POSTGRES_SERVICE_NAME"; then - printf "Docker container %s is not running.\n" "$POSTGRES_SERVICE_NAME" >&2 - return 1 -else - echo "UPGRADE: container $POSTGRES_SERVICE_NAME running." -fi - # Check origin database is in the local postgres DB_EXISTS=$(docker exec -it -u 70 $POSTGRES_SERVICE_NAME psql -tc "SELECT 1 FROM pg_database WHERE datname = '$ORIGIN_DB_NAME'" | tr -d '[:space:]') if [ "$DB_EXISTS" ]; then