imp: remove add-ons uninstall process

uninstall of add-ons is way too complicated due to dependencies.
the scripts now just list the add-ons that are installed in the
origin database, but not available in the final Odoo docker image.
This commit is contained in:
Stéphan Sainléger
2024-12-17 23:26:23 +01:00
parent 5dea543bb1
commit 7aeeccf88e

View File

@@ -6,26 +6,7 @@ DB_NAME="$2"
DB_FINALE_MODEL="$3" DB_FINALE_MODEL="$3"
DB_FINALE_SERVICE="$4" DB_FINALE_SERVICE="$4"
# Function to ask if the add-ons list to uninstall is OK echo "Start database preparation"
ask_confirmation() {
while true; do
echo "
Do you accept to uninstall all these add-ons? (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!"; return 0;;
[Nn] ) echo "
Upgrade cancelled!"; return 1;;
* ) echo "Please answer by Y or N.";;
esac
done
}
# Main execution
echo "UPGRADE: Start database preparation"
# Check POSTGRES container is running # Check POSTGRES container is running
if ! docker ps | grep -q "$DB_CONTAINER_NAME"; then if ! docker ps | grep -q "$DB_CONTAINER_NAME"; then
@@ -54,24 +35,11 @@ echo "Neutralize base..."
query_postgres_container "$SQL_NEUTRALIZE" "$DB_NAME" || exit 1 query_postgres_container "$SQL_NEUTRALIZE" "$DB_NAME" || exit 1
echo "Base neutralized..." echo "Base neutralized..."
################################ #######################################
## Uninstall unwished add-ons ## ## List add-ons not in final version ##
################################ #######################################
# Add columns to_remove and dependencies # Retrieve add-ons not available on the final Odoo version
SQL_INIT=$(cat <<'EOF'
ALTER TABLE ir_module_module ADD COLUMN IF NOT EXISTS to_remove BOOLEAN;
ALTER TABLE ir_module_module ADD COLUMN IF NOT EXISTS dependencies VARCHAR;
UPDATE ir_module_module SET state = 'installed' WHERE state = 'to remove';
UPDATE ir_module_module SET to_remove = false;
UPDATE ir_module_module SET dependencies = '';
EOF
)
echo "Prepare ir.module table"
query_postgres_container "$SQL_INIT" "$DB_NAME" || exit 1
# List add-ons not available on the final Odoo version
SQL_404_ADDONS_LIST=" SQL_404_ADDONS_LIST="
SELECT module_origin.name SELECT module_origin.name
FROM ir_module_module module_origin FROM ir_module_module module_origin
@@ -86,72 +54,36 @@ SQL_404_ADDONS_LIST="
; ;
" "
echo "Retrieve 404 addons... " echo "Retrieve 404 addons... "
echo "SQL REQUEST = $SQL_404_ADDONS_LIST"
query_postgres_container "$SQL_404_ADDONS_LIST" "$DB_NAME" > 404_addons || exit 1 query_postgres_container "$SQL_404_ADDONS_LIST" "$DB_NAME" > 404_addons || exit 1
# Create combined list of add-ons not found and add-ons which must be removed
cat 404_addons force_uninstall_addons | sort | uniq > combined_addons
# Keep only the installed add-ons # Keep only the installed add-ons
INSTALLED_ADDONS="SELECT name FROM ir_module_module WHERE state='installed';" INSTALLED_ADDONS="SELECT name FROM ir_module_module WHERE state='installed';"
query_postgres_container "$INSTALLED_ADDONS" "$DB_NAME" > installed_addons || exit 1 query_postgres_container "$INSTALLED_ADDONS" "$DB_NAME" > installed_addons || exit 1
grep -Fx -f combined_addons installed_addons > addons_to_remove grep -Fx -f 404_addons installed_addons > final_404_addons
rm -f 404_addons combined_addons installed_addons rm -f 404_addons installed_addons
# Ask confirmation to uninstall the selected add-ons # Ask confirmation to uninstall the selected add-ons
echo " echo "
==== FIRST CHECK ==== ==== ADD-ONS CHECK ====
Installed add-ons to uninstall (forced OR not found in final Odoo version): Installed add-ons not available in final Odoo version:
" "
cat addons_to_remove cat final_404_addons
ask_confirmation || exit 1
# Tag the selected add-ons as "to remove"
echo "TAG the add-ons to remove..."
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 < addons_to_remove
echo $SQL_TAG_TO_REMOVE
query_postgres_container "$SQL_TAG_TO_REMOVE" "$DB_NAME" || exit 1
echo "Add-ons to be removed TAGGED."
rm -f addons_to_remove
# Identify the add-ons which depend on the add-on to uninstall
echo "Detect and tag add-ons dependencies..."
SQL_DEPENDENCIES="
UPDATE ir_module_module imm SET to_remove = true, dependencies = immd.name
FROM ir_module_module_dependency immd
WHERE immd.module_id = imm.id AND imm.state = 'installed' AND imm.to_remove = false
AND immd.name IN (
SELECT name FROM ir_module_module WHERE to_remove = True
);
"
updated=""
while [[ "$updated" != "UPDATE 0" ]]; do
updated=$(query_postgres_container "$SQL_DEPENDENCIES" "$DB_NAME") || exit 1
done;
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" "$DB_NAME" || exit 1
echo "Add-ons to remove with state 'to remove'"
# Last check on all the add-ons to be removed
echo " echo "
==== LAST CHECK! ==== Do you accept to migrate the database with all these add-ons still installed? (Y/N/R)"
Here is the whole list of add-ons to be removed: echo "Y - Yes, let's go on with the upgrade."
" echo "N - No, stop the upgrade"
SQL_ADDONS_TO_BE_REMOVED="SELECT name from ir_module_module WHERE state='to remove';" read -n 1 -p "Your choice: " choice
query_postgres_container "$SQL_ADDONS_TO_BE_REMOVED" "$DB_NAME" || exit 1 case "$choice" in
ask_confirmation || exit 1 [Yy] ) echo "
Upgrade confirmed!";;
[Nn] ) echo "
Upgrade cancelled!"; exit 1;;
* ) echo "
Please answer by Y or N.";;
esac
echo "Database successfully prepared!"
# Launch Odooo container and launch the uninstall function
echo "Launch Odoo to uninstall add-ons..."
echo "print('START ADD-ONS UNINSTALL'); self.env['ir.module.module'].search([('state', '=', 'to remove')]).button_immediate_uninstall(); print('END ADD-ONS UNINSTALL')" | compose run $ODOO_SERVICE shell --database=$DB_NAME --no-http
echo "Add-ons uninstall successful."