#!/bin/bash set -euo pipefail ODOO_SERVICE="$1" DB_NAME="$2" DB_FINALE_MODEL="$3" DB_FINALE_SERVICE="$4" TMPDIR=$(mktemp -d) trap 'rm -rf "$TMPDIR"' EXIT echo "Start database preparation" # 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 exit 1 fi 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;" "$DB_NAME" || exit 1 fi # Neutralize the database SQL_NEUTRALIZE=$(cat <<'EOF' /* Archive all the mail servers */ UPDATE fetchmail_server SET active = false; UPDATE ir_mail_server SET active = false; /* Archive all the cron */ ALTER TABLE ir_cron ADD COLUMN IF NOT EXISTS active_bkp BOOLEAN; UPDATE ir_cron SET active_bkp = active; UPDATE ir_cron SET active = False; EOF ) echo "Neutralize base..." query_postgres_container "$SQL_NEUTRALIZE" "$DB_NAME" || exit 1 echo "Base neutralized..." ####################################### ## List add-ons not in final version ## ####################################### SQL_404_ADDONS_LIST=$(cat < "${TMPDIR}/404_addons" INSTALLED_ADDONS="SELECT name FROM ir_module_module WHERE state='installed';" query_postgres_container "$INSTALLED_ADDONS" "$DB_NAME" > "${TMPDIR}/installed_addons" grep -Fx -f "${TMPDIR}/404_addons" "${TMPDIR}/installed_addons" > "${TMPDIR}/final_404_addons" || true echo " ==== ADD-ONS CHECK ==== Installed add-ons not available in final Odoo version: " cat "${TMPDIR}/final_404_addons" echo " Do you accept to migrate the database with all these add-ons still installed? (Y/N/R)" echo "Y - Yes, let's go on with the upgrade." echo "N - No, stop the upgrade" read -n 1 -p "Your choice: " choice case "$choice" in [Yy] ) echo " Let's go on!";; [Nn] ) echo " Upgrade cancelled!"; exit 1;; * ) echo " Please answer by Y or N.";; esac # Check the views PYTHON_SCRIPT=pre_migration_view_checking.py echo "Check views with script $PYTHON_SCRIPT ..." exec_python_script_in_odoo_shell "$DB_NAME" "$DB_NAME" "$PYTHON_SCRIPT" || exit 1 echo " Do you accept to migrate the database with the current views states? (Y/N/R)" echo "Y - Yes, let's go on with the upgrade." echo "N - No, stop the upgrade" read -n 1 -p "Your choice: " choice case "$choice" in [Yy] ) echo " Upgrade confirmed!";; [Nn] ) echo " Upgrade cancelled!"; exit 1;; * ) echo " Please answer by Y or N.";; esac echo "Database successfully prepared!"