diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index c8f16d02c9..002a5158a0 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -234,7 +234,7 @@ shape)) (update-container [container] - (update container :objects d/update-vals fix-line-paths))] + (d/update-when container :objects d/update-vals fix-line-paths))] (-> data (update :pages-index d/update-vals update-container) @@ -288,7 +288,9 @@ (let [[deleted objects] (clean-objects objects)] (if (and (pos? deleted) (< n 1000)) (recur (inc n) objects) - (assoc container :objects objects)))))] + (-> container + (assoc :objects objects) + (d/without-nils))))))] (-> data (update :pages-index d/update-vals clean-container) @@ -386,21 +388,20 @@ (dissoc :fill-color :fill-opacity)))) (update-container [container] - (if (contains? container :objects) - (loop [objects (:objects container) - shapes (->> (vals objects) - (filter cfh/image-shape?))] - (if-let [shape (first shapes)] - (let [{:keys [id frame-id] :as shape'} (process-shape shape)] - (if (identical? shape shape') - (recur objects (rest shapes)) - (recur (-> objects - (assoc id shape') - (d/update-when frame-id dissoc :thumbnail)) - (rest shapes)))) - (assoc container :objects objects))) - container))] - + (loop [objects (:objects container) + shapes (->> (vals objects) + (filter cfh/image-shape?))] + (if-let [shape (first shapes)] + (let [{:keys [id frame-id] :as shape'} (process-shape shape)] + (if (identical? shape shape') + (recur objects (rest shapes)) + (recur (-> objects + (assoc id shape') + (d/update-when frame-id dissoc :thumbnail)) + (rest shapes)))) + (-> container + (assoc :objects objects) + (d/without-nils)))))] (-> data (update :pages-index d/update-vals update-container) (d/update-when :components d/update-vals update-container)))) @@ -1653,6 +1654,18 @@ (update :pages-index d/update-vals update-container) (d/update-when :components d/update-vals update-container)))) +(defmethod migrate-data "0017-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. + + (letfn [(update-container [container] + (d/without-nils container))] + (d/update-when data :components d/update-vals update-container))) + (def available-migrations (into (d/ordered-set) ["legacy-2" @@ -1724,4 +1737,5 @@ "0013-fix-component-path" "0014-fix-tokens-lib-duplicate-ids" "0015-clear-invalid-strokes-and-fills" - "0016-clear-pages-and-shapes"])) + "0016-clear-pages-and-shapes" + "0017-clear-components-nil-objects"]))