From b6fd05104ab61f60ca1fc0edf707ac8c794fedeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Mon, 10 Aug 2026 17:06:34 +0200 Subject: [PATCH] [CLN] finalize_db: purge resized partner images and orphaned ``ir_attachment`` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete the four thumbnail sizes (``image_128``, ``image_256``, ``image_512``, ``image_1024``) from ``ir_attachment`` for ``res.partner`` records. Odoo 13+ regenerates all thumbnails automatically from ``image_1920`` on the next partner write. Also delete attachments whose ``res_model`` is ``NULL`` (orphaned ``factur-x.xml``, SCSS, ICS files) — these have no associated record and consume ~48 MB of filestore space. --- scripts/finalize_db.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/finalize_db.sh b/scripts/finalize_db.sh index dcdefb4..0048081 100755 --- a/scripts/finalize_db.sh +++ b/scripts/finalize_db.sh @@ -29,6 +29,29 @@ query_postgres_container "$CLEANUP_SQL" "$DB_NAME" echo "Purging ir_logging..." query_postgres_container "TRUNCATE ir_logging;" "$DB_NAME" +# ──────────────────────────────────────────────────────────── +# Purge resized partner images (128, 256, 512, 1024) and +# attachments with no res_model (orphaned factur-x, CSS, ICS). +# Odoo 13+ regenerates thumbnails automatically from +# image_1920 on the next partner write, so only the full-size +# source needs to be kept. +# ──────────────────────────────────────────────────────────── +echo "Purging resized partner images and orphaned attachments..." +PURGE_ATTACHMENTS_SQL=$(cat <<'EOF' +DELETE FROM ir_attachment +WHERE res_model = 'res.partner' + AND (name ILIKE '%image_128%' + OR name ILIKE '%image_256%' + OR name ILIKE '%image_512%' + OR name ILIKE '%image_1024%'); + +DELETE FROM ir_attachment +WHERE (res_model IS NULL OR res_model = '') + AND store_fname IS NOT NULL; +EOF +) +query_postgres_container "$PURGE_ATTACHMENTS_SQL" "$DB_NAME" + # ──────────────────────────────────────────────────────────── # Fix orphan ir_filters pointing to deleted ir_actions #