🐛 Add migration for clearing :objects nil from components

on the local library
This commit is contained in:
Andrey Antukh 2025-10-14 17:14:25 +02:00
parent 17376dfa3f
commit c9dcc8a4ee

View File

@ -231,7 +231,7 @@
shape)) shape))
(update-container [container] (update-container [container]
(update container :objects d/update-vals fix-line-paths))] (d/update-when container :objects d/update-vals fix-line-paths))]
(-> data (-> data
(update :pages-index d/update-vals update-container) (update :pages-index d/update-vals update-container)
@ -285,7 +285,9 @@
(let [[deleted objects] (clean-objects objects)] (let [[deleted objects] (clean-objects objects)]
(if (and (pos? deleted) (< n 1000)) (if (and (pos? deleted) (< n 1000))
(recur (inc n) objects) (recur (inc n) objects)
(assoc container :objects objects)))))] (-> container
(assoc :objects objects)
(d/without-nils))))))]
(-> data (-> data
(update :pages-index d/update-vals clean-container) (update :pages-index d/update-vals clean-container)
@ -383,21 +385,20 @@
(dissoc :fill-color :fill-opacity)))) (dissoc :fill-color :fill-opacity))))
(update-container [container] (update-container [container]
(if (contains? container :objects) (loop [objects (:objects container)
(loop [objects (:objects container) shapes (->> (vals objects)
shapes (->> (vals objects) (filter cfh/image-shape?))]
(filter cfh/image-shape?))] (if-let [shape (first shapes)]
(if-let [shape (first shapes)] (let [{:keys [id frame-id] :as shape'} (process-shape shape)]
(let [{:keys [id frame-id] :as shape'} (process-shape shape)] (if (identical? shape shape')
(if (identical? shape shape') (recur objects (rest shapes))
(recur objects (rest shapes)) (recur (-> objects
(recur (-> objects (assoc id shape')
(assoc id shape') (d/update-when frame-id dissoc :thumbnail))
(d/update-when frame-id dissoc :thumbnail)) (rest shapes))))
(rest shapes)))) (-> container
(assoc container :objects objects))) (assoc :objects objects)
container))] (d/without-nils)))))]
(-> data (-> data
(update :pages-index d/update-vals update-container) (update :pages-index d/update-vals update-container)
(d/update-when :components d/update-vals update-container)))) (d/update-when :components d/update-vals update-container))))
@ -1607,6 +1608,14 @@
(update :pages-index d/update-vals update-container) (update :pages-index d/update-vals update-container)
(d/update-when :components d/update-vals update-container)))) (d/update-when :components d/update-vals update-container))))
(defmethod migrate-data "0014-clear-components-nil-objects"
[data _]
;; Because of a bug in migrations, several files have migrations
;; applied in an incorrect order and because of other bug on old
;; migrations, some files have components with `:objects` with `nil`
;; as value; this migration fixes it.
(d/update-when data :components d/update-vals d/without-nils))
(def available-migrations (def available-migrations
(into (d/ordered-set) (into (d/ordered-set)
["legacy-2" ["legacy-2"
@ -1675,4 +1684,5 @@
"0010-fix-swap-slots-pointing-non-existent-shapes" "0010-fix-swap-slots-pointing-non-existent-shapes"
"0011-fix-invalid-text-touched-flags" "0011-fix-invalid-text-touched-flags"
"0012-fix-position-data" "0012-fix-position-data"
"0013-clear-invalid-strokes-and-fills"])) "0013-clear-invalid-strokes-and-fills"
"0014-clear-components-nil-objects"]))