[IMP] combine SQL queries into single transaction with documentation
Merge three separate SQL queries into one for better performance: - 1 database connection instead of 3 - Atomic execution of all cleanup operations Added detailed SQL comments explaining each operation: - DROP SEQUENCE: Why stale sequences prevent Odoo startup - UPDATE ir_ui_view: Why website templates are reset except pages - DELETE ir_attachment: Why compiled assets must be purged Also changed DROP SEQUENCE to DROP SEQUENCE IF EXISTS to avoid errors if sequences don't exist.
This commit is contained in:
@@ -4,42 +4,41 @@ set -euo pipefail
|
|||||||
DB_NAME="$1"
|
DB_NAME="$1"
|
||||||
ODOO_SERVICE="$2"
|
ODOO_SERVICE="$2"
|
||||||
|
|
||||||
FINALE_SQL=$(cat <<'EOF'
|
echo "Running SQL cleanup..."
|
||||||
/*Delete sequences that prevent Odoo to start*/
|
CLEANUP_SQL=$(cat <<'EOF'
|
||||||
drop sequence base_registry_signaling;
|
-- Drop sequences that prevent Odoo from starting.
|
||||||
drop sequence base_cache_signaling;
|
-- These sequences are recreated by Odoo on startup but stale values
|
||||||
EOF
|
-- from the old version can cause conflicts.
|
||||||
)
|
DROP SEQUENCE IF EXISTS base_registry_signaling;
|
||||||
query_postgres_container "$FINALE_SQL" "$DB_NAME" || exit 1
|
DROP SEQUENCE IF EXISTS base_cache_signaling;
|
||||||
|
|
||||||
# Fix duplicated views
|
-- Reset website templates to their original state.
|
||||||
PYTHON_SCRIPT=post_migration_fix_duplicated_views.py
|
-- Views with arch_fs (file source) that have been customized (arch_db not null)
|
||||||
echo "Remove duplicated views with script $PYTHON_SCRIPT ..."
|
-- are reset to use the file version, EXCEPT for actual website pages which
|
||||||
exec_python_script_in_odoo_shell "$DB_NAME" "$DB_NAME" "$PYTHON_SCRIPT" || exit 1
|
-- contain user content that must be preserved.
|
||||||
|
|
||||||
# Reset all website templates with custom content
|
|
||||||
FINALE_SQL_2=$(cat <<'EOF'
|
|
||||||
UPDATE ir_ui_view
|
UPDATE ir_ui_view
|
||||||
SET arch_db = NULL
|
SET arch_db = NULL
|
||||||
WHERE arch_fs IS NOT NULL
|
WHERE arch_fs IS NOT NULL
|
||||||
AND arch_fs LIKE 'website/%'
|
AND arch_fs LIKE 'website/%'
|
||||||
AND arch_db IS NOT NULL
|
AND arch_db IS NOT NULL
|
||||||
AND id NOT IN (SELECT view_id FROM website_page);
|
AND id NOT IN (SELECT view_id FROM website_page);
|
||||||
EOF
|
|
||||||
)
|
|
||||||
query_postgres_container "$FINALE_SQL_2" "$DB_NAME" || exit 1
|
|
||||||
|
|
||||||
# Purge QWeb cache from compiled assets
|
-- Purge compiled frontend assets (CSS/JS bundles).
|
||||||
FINALE_SQL_3=$(cat <<'EOF'
|
-- These cached files reference old asset versions and must be regenerated
|
||||||
|
-- by Odoo after migration to avoid broken stylesheets and scripts.
|
||||||
DELETE FROM ir_attachment
|
DELETE FROM ir_attachment
|
||||||
WHERE name LIKE '/web/assets/%'
|
WHERE name LIKE '/web/assets/%'
|
||||||
OR name LIKE '%.assets_%'
|
OR name LIKE '%.assets_%'
|
||||||
OR (res_model = 'ir.ui.view' AND mimetype = 'text/css');
|
OR (res_model = 'ir.ui.view' AND mimetype = 'text/css');
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
query_postgres_container "$FINALE_SQL_3" "$DB_NAME" || exit 1
|
query_postgres_container "$CLEANUP_SQL" "$DB_NAME"
|
||||||
|
|
||||||
# Uninstall obsolette add-ons
|
PYTHON_SCRIPT=post_migration_fix_duplicated_views.py
|
||||||
|
echo "Remove duplicated views with script $PYTHON_SCRIPT ..."
|
||||||
|
exec_python_script_in_odoo_shell "$DB_NAME" "$DB_NAME" "$PYTHON_SCRIPT"
|
||||||
|
|
||||||
|
# Uninstall obsolete add-ons
|
||||||
PYTHON_SCRIPT=post_migration_cleanup_obsolete_modules.py
|
PYTHON_SCRIPT=post_migration_cleanup_obsolete_modules.py
|
||||||
echo "Uninstall obsolete add-ons with script $PYTHON_SCRIPT ..."
|
echo "Uninstall obsolete add-ons with script $PYTHON_SCRIPT ..."
|
||||||
exec_python_script_in_odoo_shell "$DB_NAME" "$DB_NAME" "$PYTHON_SCRIPT" || exit 1
|
exec_python_script_in_odoo_shell "$DB_NAME" "$DB_NAME" "$PYTHON_SCRIPT" || exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user