Compare commits
2 Commits
1d75a0f9db
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e06d750b74 | ||
|
|
0c096bb5ff |
@@ -32,16 +32,24 @@ query_postgres_container "$CLEANUP_SQL" "$DB_NAME"
|
||||
# ────────────────────────────────────────────────────────────
|
||||
echo "Purging ir.ui.view images orphaned of their parent view and unreferenced in any arch_db..."
|
||||
PURGE_VIEW_IMAGES_SQL=$(cat <<'EOF'
|
||||
DELETE FROM ir_attachment a
|
||||
WHERE a.res_model = 'ir.ui.view'
|
||||
AND a.mimetype LIKE 'image/%'
|
||||
AND a.store_fname IS NOT NULL
|
||||
AND a.res_id NOT IN (SELECT id FROM ir_ui_view)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM ir_ui_view v
|
||||
WHERE v.arch_db::text ILIKE '%web/image/' || a.id || '%'
|
||||
OR v.arch_db::text ILIKE '%web/content/' || a.id || '%'
|
||||
);
|
||||
DO $$
|
||||
DECLARE purged int;
|
||||
BEGIN
|
||||
WITH refs AS (
|
||||
SELECT DISTINCT (m[1])::bigint AS ref_id
|
||||
FROM ir_ui_view v
|
||||
CROSS JOIN LATERAL regexp_matches(
|
||||
COALESCE(v.arch_db::text, ''), '/web/(?:image|content)/(\d+)', 'g') AS m
|
||||
)
|
||||
DELETE FROM ir_attachment a
|
||||
WHERE a.res_model = 'ir.ui.view'
|
||||
AND a.mimetype LIKE 'image/%'
|
||||
AND a.store_fname IS NOT NULL
|
||||
AND a.res_id NOT IN (SELECT id FROM ir_ui_view)
|
||||
AND NOT EXISTS (SELECT 1 FROM refs r WHERE r.ref_id = a.id);
|
||||
GET DIAGNOSTICS purged = ROW_COUNT;
|
||||
RAISE NOTICE 'Purged % orphaned ir.ui.view image attachments', purged;
|
||||
END $$;
|
||||
EOF
|
||||
)
|
||||
query_postgres_container "$PURGE_VIEW_IMAGES_SQL" "$DB_NAME"
|
||||
|
||||
@@ -132,6 +132,11 @@ DECLARE
|
||||
deleted_imd INTEGER;
|
||||
deleted_tpl INTEGER;
|
||||
BEGIN
|
||||
IF to_regclass('theme_ir_ui_view') IS NULL THEN
|
||||
RAISE NOTICE 'Table theme_ir_ui_view does not exist, skipping stale view cleanup.';
|
||||
RETURN;
|
||||
END IF;
|
||||
|
||||
WITH targets AS (
|
||||
SELECT id FROM theme_ir_ui_view
|
||||
WHERE inherit_id LIKE 'ir.ui.view,%'
|
||||
@@ -166,6 +171,46 @@ EOF
|
||||
echo "SQL command = $PRE_MIGRATE_SQL_5"
|
||||
query_postgres_container "$PRE_MIGRATE_SQL_5" ou17 || exit 1
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
# Drop mail.tracking.value rows referencing event.registration.mobile
|
||||
#
|
||||
# In Odoo 17 the field event.registration.mobile is removed (OpenUpgrade:
|
||||
# "event / event.registration / mobile (char) : DEL"). During _process_end,
|
||||
# Odoo unlinks the now-orphan ir.model.fields row. mail's ir_model_fields
|
||||
# unlink() override iterates the mail.tracking.value rows pointing to it and
|
||||
# calls event.registration._mail_track_get_field_sequence('mobile'), which
|
||||
# does self._fields['mobile'] -> KeyError: 'mobile', aborting the registry:
|
||||
#
|
||||
# KeyError: 'mobile' (mail/models/models.py, _mail_track_get_field_sequence)
|
||||
#
|
||||
# The OpenUpgrade event script deletes the field but leaves its tracking
|
||||
# values, so any DB that tracked this field crashes. We delete those tracking
|
||||
# values beforehand so the field unlinks cleanly.
|
||||
# Scoped strictly to event.registration.mobile. Idempotent.
|
||||
# NOTE: this runs before -u all, so the FK column is still named 'field'
|
||||
# (mail renames it to 'field_id' during the 16->17 upgrade).
|
||||
# ────────────────────────────────────────────────────────────
|
||||
PRE_MIGRATE_SQL_6=$(cat <<'EOF'
|
||||
DO $$
|
||||
DECLARE
|
||||
deleted_count INTEGER;
|
||||
BEGIN
|
||||
WITH del AS (
|
||||
DELETE FROM mail_tracking_value
|
||||
WHERE field IN (
|
||||
SELECT id FROM ir_model_fields
|
||||
WHERE model = 'event.registration' AND name = 'mobile'
|
||||
)
|
||||
RETURNING id
|
||||
)
|
||||
SELECT count(*) INTO deleted_count FROM del;
|
||||
RAISE NOTICE 'Removed % mail_tracking_value row(s) for event.registration.mobile', deleted_count;
|
||||
END $$;
|
||||
EOF
|
||||
)
|
||||
echo "SQL command = $PRE_MIGRATE_SQL_6"
|
||||
query_postgres_container "$PRE_MIGRATE_SQL_6" ou17 || exit 1
|
||||
|
||||
# Copy filestores
|
||||
copy_filestore ou16 ou16 ou17 ou17 || exit 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user