diff --git a/13.0/pre_upgrade.sh b/13.0/pre_upgrade.sh index cea3d8b..2342186 100755 --- a/13.0/pre_upgrade.sh +++ b/13.0/pre_upgrade.sh @@ -1,24 +1,5 @@ #!/bin/bash -DB_CONTAINER_NAME="lokavaluto_postgres_1" - -# Function to launch an SQL request to the postgres container -query_postgres_container(){ - local query="$1" - if [ -z "$query" ]; then - return 0 - fi - local result - if ! result=$(docker exec -u 70 "$DB_CONTAINER_NAME" psql -d ou13 -t -A -c "$query" 2>&1); then - printf "Failed to execute SQL query: %s\n" "$query" >&2 - printf "Error: %s\n" "$result" >&2 - exit 1 - fi - # Remove leading/trailing whitespace from result - result=$(echo "$result" | xargs) - echo "$result" -} - echo "Prepare migration to 13.0..." # Copy database @@ -34,7 +15,7 @@ UPDATE ir_model_data SET model = 'ir.ui.view' WHERE module = 'website_sale' AND UPDATE ir_model_data SET model = 'ir.ui.view' WHERE module = 'website_sale' AND name = 'product_comment'; EOF ) -query_postgres_container "$PRE_MIGRATE_SQL" +query_postgres_container "$PRE_MIGRATE_SQL" ou13 || exit 1 # Copy filestores diff --git a/14.0/pre_upgrade.sh b/14.0/pre_upgrade.sh index efa2561..96dc64e 100755 --- a/14.0/pre_upgrade.sh +++ b/14.0/pre_upgrade.sh @@ -1,24 +1,5 @@ #!/bin/bash -DB_CONTAINER_NAME="lokavaluto_postgres_1" - -# Function to launch an SQL request to the postgres container -query_postgres_container(){ - local query="$1" - if [ -z "$query" ]; then - return 0 - fi - local result - if ! result=$(docker exec -u 70 "$DB_CONTAINER_NAME" psql -d ou14 -t -A -c "$query" 2>&1); then - printf "Failed to execute SQL query: %s\n" "$query" >&2 - printf "Error: %s\n" "$result" >&2 - exit 1 - fi - # Remove leading/trailing whitespace from result - result=$(echo "$result" | xargs) - echo "$result" -} - echo "Prepare migration to 14.0..." # Copy database @@ -26,7 +7,7 @@ docker exec -u 70 "$DB_CONTAINER_NAME" pgm cp -f ou13 ou14@ou14 # Execute SQL pre-migration commands PRE_MIGRATE_SQL="" -query_postgres_container "$PRE_MIGRATE_SQL" +query_postgres_container "$PRE_MIGRATE_SQL" ou14 || exit 1 # Copy filestores diff --git a/15.0/pre_upgrade.sh b/15.0/pre_upgrade.sh index 05ae7b1..6c13ec5 100755 --- a/15.0/pre_upgrade.sh +++ b/15.0/pre_upgrade.sh @@ -1,24 +1,5 @@ #!/bin/bash -DB_CONTAINER_NAME="lokavaluto_postgres_1" - -# Function to launch an SQL request to the postgres container -query_postgres_container(){ - local query="$1" - if [ -z "$query" ]; then - return 0 - fi - local result - - if ! result=$(docker exec -u 70 "$DB_CONTAINER_NAME" psql -d ou15 -t -A -c "$query" 2>&1); then - printf "Failed to execute SQL query: %s\n" "$query" >&2 - printf "Error: %s\n" "$result" >&2 - exit 1 - fi - # Remove leading/trailing whitespace from result - result=$(echo "$result" | xargs) -} - echo "Prepare migration to 15.0..." # Copy database @@ -32,7 +13,7 @@ DELETE FROM ir_model_data WHERE module = 'base' AND name = 'module_account_usabi EOF ) echo "SQL command = $PRE_MIGRATE_SQL" -query_postgres_container "$PRE_MIGRATE_SQL" >&1 +query_postgres_container "$PRE_MIGRATE_SQL" ou15 || exit 1 # Copy filestores diff --git a/16.0/pre_upgrade.sh b/16.0/pre_upgrade.sh index edf6b80..861de0b 100755 --- a/16.0/pre_upgrade.sh +++ b/16.0/pre_upgrade.sh @@ -1,24 +1,5 @@ #!/bin/bash -DB_CONTAINER_NAME="lokavaluto_postgres_1" - -# Function to launch an SQL request to the postgres container -query_postgres_container(){ - local query="$1" - if [ -z "$query" ]; then - return 0 - fi - local result - if ! result=$(docker exec -u 70 "$DB_CONTAINER_NAME" psql -d ou16 -t -A -c "$query" 2>&1); then - printf "Failed to execute SQL query: %s\n" "$query" >&2 - printf "Error: %s\n" "$result" >&2 - exit 1 - fi - # Remove leading/trailing whitespace from result - result=$(echo "$result" | xargs) - echo "$result" -} - echo "Prepare migration to 16.0..." # Copy database @@ -40,7 +21,7 @@ WHERE id IN ( EOF ) echo "SQL command = $PRE_MIGRATE_SQL" -query_postgres_container "$PRE_MIGRATE_SQL" +query_postgres_container "$PRE_MIGRATE_SQL" ou16 || exit 1 # Copy filestores diff --git a/finalize_db.sh b/finalize_db.sh index 1a95daa..60e3cdf 100755 --- a/finalize_db.sh +++ b/finalize_db.sh @@ -2,32 +2,14 @@ DB_NAME="$1" ODOO_SERVICE="$2" -DB_CONTAINER_NAME="lokavaluto_postgres_1" - -# Function to launch an SQL request to the postgres container -query_postgres_container(){ - local query="$1" - if [ "$query" ]; then - return 0 - fi - local result - if ! result=$(docker exec -u 70 "$DB_CONTAINER_NAME" psql -d "$DB_NAME" -t -A -c "$query" 2>&1); then - printf "Failed to execute SQL query: %s\n" "$query" >&2 - printf "Error: %s\n" "$result" >&2 - exit 1 - fi - # Remove leading/trailing whitespace from result - result=$(echo "$result" | xargs) - echo "$result" -} FINALE_SQL=$(cat <<'EOF' -/*Delte sequences that prevent Odoo to start*/ +/*Delete sequences that prevent Odoo to start*/ drop sequence base_registry_signaling; drop sequence base_cache_signaling; EOF ) -query_postgres_container "$FINALE_SQL" +query_postgres_container "$FINALE_SQL" "$DB_NAME" || exit 1 # Give back the right to user to access to the tables diff --git a/prepare_db.sh b/prepare_db.sh index 33c87c1..b375e6a 100755 --- a/prepare_db.sh +++ b/prepare_db.sh @@ -5,25 +5,6 @@ ODOO_SERVICE="$1" DB_NAME="$2" DB_FINALE_MODEL="$3" DB_FINALE_SERVICE="$4" -DB_CONTAINER_NAME="lokavaluto_postgres_1" - -# Function to launch an SQL request to the postgres container -query_postgres_container(){ - local query="$1" - if [ -z "$query" ]; then - return 0 - fi - local result - if ! result=$(docker exec -u 70 $DB_CONTAINER_NAME psql -d $DB_NAME -t -A -c "$query" 2>&1); then - printf "Failed to execute SQL query: %s\n" "$query" >&2 - printf "Error: %s\n" "$result" >&2 - exit 1 - fi - # Remove leading/trailing whitespace from result - result=$(echo "$result" | xargs) - echo "$result" -} - # Function to display the combined list of add-ons to uninstall display_combined_list(){ @@ -69,9 +50,9 @@ if ! docker ps | grep -q "$DB_CONTAINER_NAME"; then return 1 fi -EXT_EXISTS=$(query_postgres_container "SELECT 1 FROM pg_extension WHERE extname = 'dblink'") || exit 1 +EXT_EXISTS=$(query_postgres_container "SELECT 1 FROM pg_extension WHERE extname = 'dblink'" "$DB_NAME") || exit 1 if [ "$EXT_EXISTS" != "1" ]; then - query_postgres_container "CREATE EXTENSION dblink;" || exit 1 + query_postgres_container "CREATE EXTENSION dblink;" "$DB_NAME" || exit 1 fi # Neutralize the database @@ -87,7 +68,7 @@ UPDATE ir_cron SET active = False; EOF ) echo "Neutralize base..." -query_postgres_container "$SQL_NEUTRALIZE" || exit 1 +query_postgres_container "$SQL_NEUTRALIZE" "$DB_NAME" || exit 1 echo "Base neutralized..." ################################ @@ -104,7 +85,7 @@ UPDATE ir_module_module SET dependencies = ''; EOF ) echo "Prepare ir.module table" -query_postgres_container "$SQL_INIT" || exit 1 +query_postgres_container "$SQL_INIT" "$DB_NAME" || exit 1 # List add-ons not available on the final Odoo version @@ -122,7 +103,7 @@ SQL_404_ADDONS_LIST=" ; " echo "Retrieve 404 addons... " -query_postgres_container "$SQL_404_ADDONS_LIST" > 404_addons || exit 1 +query_postgres_container "$SQL_404_ADDONS_LIST" "$DB_NAME" > 404_addons || exit 1 # Ask confirmation to uninstall the selected add-ons @@ -144,7 +125,7 @@ SQL_TAG_TO_REMOVE="" while IFS= read -r name; do SQL_TAG_TO_REMOVE+="UPDATE ir_module_module SET to_remove = TRUE WHERE name = '$name' AND state = 'installed';" done < combined_addons -query_postgres_container "$SQL_TAG_TO_REMOVE" || exit 1 +query_postgres_container "$SQL_TAG_TO_REMOVE" "$DB_NAME" || exit 1 echo "Add-ons to be removed TAGGED." @@ -160,7 +141,7 @@ SQL_DEPENDENCIES=" " updated="" while [[ "$updated" != "UPDATE 0" ]]; do - updated=$(query_postgres_container "$SQL_DEPENDENCIES") || exit 1 + updated=$(query_postgres_container "$SQL_DEPENDENCIES" "$DB_NAME") || exit 1 done; echo "All dependencies to remove TAGGED" @@ -168,7 +149,7 @@ echo "All dependencies to remove TAGGED" # Change state of add-ons to remove echo "Change state of all add-ons to remove..." SQL_UPDATE_STATE="UPDATE ir_module_module SET state = 'to remove' WHERE to_remove = TRUE AND state = 'installed';" -query_postgres_container "$SQL_UPDATE_STATE" || exit 1 +query_postgres_container "$SQL_UPDATE_STATE" "$DB_NAME" || exit 1 echo "Add-ons to remove with state 'to remove'" diff --git a/upgrade.sh b/upgrade.sh index 5e527b1..d5c6103 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -21,7 +21,7 @@ FINALE_DB_NAME="ou${FINAL_VERSION}" FINALE_SERVICE_NAME="${FINALE_DB_NAME}" # Service postgres name -POSTGRES_SERVICE_NAME="lokavaluto_postgres_1" +export POSTGRES_SERVICE_NAME="lokavaluto_postgres_1" ############################################# # DISPLAYS ALL INPUTS PARAMETERS @@ -43,6 +43,25 @@ echo "Finale service name ...... $FINALE_SERVICE_NAME" echo "Postgres service name .... $POSTGRES_SERVICE_NAME" + +# Function to launch an SQL request to the postgres container +query_postgres_container(){ + local QUERY="$1" + local DB_NAME="$2" + if [ -z "$QUERY" ]; then + return 0 + fi + local result + if ! result=$(docker exec -u 70 "$POSTGRES_SERVICE_NAME" psql -d "$DB_NAME" -t -A -c "$QUERY"); then + printf "Failed to execute SQL query: %s\n" "$query" >&2 + printf "Error: %s\n" "$result" >&2 + exit 1 + fi + echo "$result" +} +export -f query_postgres_container + + ############################################## # CHECKS ALL NEEDED COMPONENTS ARE AVAILABLE # ##############################################