From b2c45f6e1da98b5820b376cf10e8f5f4f262f18f Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Thu, 11 Dec 2025 17:10:09 +0100 Subject: [PATCH] :bug: Fix migration and repair for nil ids --- common/src/app/common/files/migrations.cljc | 18 ++++++++++++++---- common/src/app/common/files/repair.cljc | 15 ++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index b6c1ddb49c..2845303e9f 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1775,7 +1775,7 @@ (contains? component :objects)) (dissoc component :objects) component))] - (d/update-when data :components check-component))) + (d/update-when data :components d/update-vals check-component))) (defmethod migrate-data "0018-sync-component-id-with-near-main" [data _] @@ -1788,9 +1788,18 @@ (if (and (some? ref-shape) (or (not= (:component-id shape) (:component-id ref-shape)) (not= (:component-file shape) (:component-file ref-shape)))) - (assoc shape - :component-id (:component-id ref-shape) - :component-file (:component-file ref-shape)) + (cond-> shape + (some? (:component-id ref-shape)) + (assoc :component-id (:component-id ref-shape)) + + (nil? (:component-id ref-shape)) + (dissoc :component-id) + + (some? (:component-file ref-shape)) + (assoc :component-file (:component-file ref-shape)) + + (nil? (:component-file ref-shape)) + (dissoc :component-file)) shape)) shape)) @@ -1799,6 +1808,7 @@ (-> data (update :pages-index d/update-vals update-page)))) + (def available-migrations (into (d/ordered-set) ["legacy-2" diff --git a/common/src/app/common/files/repair.cljc b/common/src/app/common/files/repair.cljc index 100090a8ed..c8e3d172e3 100644 --- a/common/src/app/common/files/repair.cljc +++ b/common/src/app/common/files/repair.cljc @@ -340,9 +340,18 @@ ; Set the component-id and component-file to the ones of the near main (log/debug :hint (str " -> set component-id to " (:component-id args))) (log/debug :hint (str " -> set component-file to " (:component-file args))) - (assoc shape - :component-id (:component-id args) - :component-file (:component-file args)))] + (cond-> shape + (some? (:component-id args)) + (assoc :component-id (:component-id args)) + + (nil? (:component-id args)) + (dissoc :component-id) + + (some? (:component-file args)) + (assoc :component-file (:component-file args)) + + (nil? (:component-file args)) + (dissoc :component-file)))] (log/dbg :hint "repairing shape :component-id-mismatch" :id (:id shape) :name (:name shape) :page-id page-id) (-> (pcb/empty-changes nil page-id)