From 928dcf5cb8601f5220ffdbf64a8d71fcfc43595b Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 14 Oct 2025 17:40:42 +0200 Subject: [PATCH 1/2] :bug: Fix migrations set decoding on binfile import that causes incorrect migration ordering on the table --- common/src/app/common/schema.cljc | 11 ++++++++--- common/src/app/common/types/file.cljc | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/schema.cljc b/common/src/app/common/schema.cljc index 54edcf599e..0af10d0f3f 100644 --- a/common/src/app/common/schema.cljc +++ b/common/src/app/common/schema.cljc @@ -420,7 +420,7 @@ :min 0 :max 1 :compile - (fn [{:keys [kind max min] :as props} children _] + (fn [{:keys [kind max min ordered] :as props} children _] (let [kind (or (last children) kind) pred @@ -456,18 +456,23 @@ (fn [value] (every? pred value))) + empty-set + (if ordered + (d/ordered-set) + #{}) + decode (fn [v] (cond (string? v) (let [v (str/split v #"[\s,]+")] - (into #{} xf:filter-word-strings v)) + (into empty-set xf:filter-word-strings v)) (set? v) v (coll? v) - (into #{} v) + (into empty-set v) :else v)) diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index f7ee4c06de..066f048526 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -106,7 +106,7 @@ [:version :int] [:features ::cfeat/features] [:migrations {:optional true} - [::sm/set :string]]]) + [::sm/set {:ordered true} :string]]]) (sm/register! ::data schema:data) (sm/register! ::file schema:file) From 1b6a833166fc0df1c1b4239d0396d7063cd64f4e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 14 Oct 2025 10:30:13 +0200 Subject: [PATCH 2/2] :bug: Add migration for fix fills on position-data --- common/src/app/common/files/migrations.cljc | 142 ++++++++++---------- 1 file changed, 72 insertions(+), 70 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index f368db6069..c864937c83 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1433,74 +1433,6 @@ (update :pages-index d/update-vals update-container) (d/update-when :components d/update-vals update-container)))) -(def ^:private valid-stroke? - (sm/lazy-validator cts/schema:stroke)) - -(defmethod migrate-data "0007-clear-invalid-strokes-and-fills-v2" - [data _] - (letfn [(clear-color-image [image] - (select-keys image types.color/image-attrs)) - - (clear-color-gradient [gradient] - (select-keys gradient types.color/gradient-attrs)) - - (clear-stroke [stroke] - (-> stroke - (select-keys cts/stroke-attrs) - (d/update-when :stroke-color-gradient clear-color-gradient) - (d/update-when :stroke-image clear-color-image) - (d/update-when :stroke-style #(if (#{:svg :none} %) :solid %)))) - - (fix-strokes [strokes] - (->> (map clear-stroke strokes) - (filterv valid-stroke?))) - - ;; Fixes shapes with nested :fills in the :fills attribute - ;; introduced in a migration `0006-fix-old-texts-fills` when - ;; types.text/transform-nodes with identity pred was broken - (remove-nested-fills [[fill :as fills]] - (if (and (= 1 (count fills)) - (contains? fill :fills)) - (:fills fill) - fills)) - - (clear-fill [fill] - (-> fill - (select-keys types.fills/fill-attrs) - (d/update-when :fill-image clear-color-image) - (d/update-when :fill-color-gradient clear-color-gradient))) - - (fix-fills [fills] - (->> fills - (remove-nested-fills) - (map clear-fill) - (filterv valid-fill?))) - - (fix-object [object] - (-> object - (d/update-when :strokes fix-strokes) - (d/update-when :fills fix-fills))) - - (fix-text-content [content] - (->> content - (types.text/transform-nodes types.text/is-content-node? fix-object) - (types.text/transform-nodes types.text/is-paragraph-set-node? #(dissoc % :fills)))) - - (update-shape [object] - (-> object - (fix-object) - ;; The text shape also can has strokes and fils on the - ;; text fragments so we need to fix them there - (cond-> (cfh/text-shape? object) - (update :content fix-text-content)))) - - (update-container [container] - (d/update-when container :objects d/update-vals update-shape))] - - (-> data - (update :pages-index d/update-vals update-container) - (d/update-when :components d/update-vals update-container)))) - (defmethod migrate-data "0008-fix-library-colors-v4" [data _] (letfn [(clear-color-opacity [color] @@ -1605,6 +1537,76 @@ (update :pages-index d/update-vals update-container) (d/update-when :components d/update-vals update-container)))) +(def ^:private valid-stroke? + (sm/lazy-validator cts/schema:stroke)) + +(defmethod migrate-data "0013-clear-invalid-strokes-and-fills" + [data _] + (letfn [(clear-color-image [image] + (select-keys image types.color/image-attrs)) + + (clear-color-gradient [gradient] + (select-keys gradient types.color/gradient-attrs)) + + (clear-stroke [stroke] + (-> stroke + (select-keys cts/stroke-attrs) + (d/update-when :stroke-color-gradient clear-color-gradient) + (d/update-when :stroke-image clear-color-image) + (d/update-when :stroke-style #(if (#{:svg :none} %) :solid %)))) + + (fix-strokes [strokes] + (->> (map clear-stroke strokes) + (filterv valid-stroke?))) + + ;; Fixes shapes with nested :fills in the :fills attribute + ;; introduced in a migration `0006-fix-old-texts-fills` when + ;; types.text/transform-nodes with identity pred was broken + (remove-nested-fills [[fill :as fills]] + (if (and (= 1 (count fills)) + (contains? fill :fills)) + (:fills fill) + fills)) + + (clear-fill [fill] + (-> fill + (select-keys types.fills/fill-attrs) + (d/update-when :fill-image clear-color-image) + (d/update-when :fill-color-gradient clear-color-gradient))) + + (fix-fills [fills] + (->> fills + (remove-nested-fills) + (map clear-fill) + (filterv valid-fill?))) + + (fix-object [object] + (-> object + (d/update-when :strokes fix-strokes) + (d/update-when :fills fix-fills))) + + (fix-text-content [content] + (->> content + (types.text/transform-nodes types.text/is-content-node? fix-object) + (types.text/transform-nodes types.text/is-paragraph-set-node? #(dissoc % :fills)))) + + (update-shape [object] + (-> object + (fix-object) + (d/update-when :position-data #(mapv fix-object %)) + + ;; The text shape can also have strokes and fills on + ;; the text fragments, so we need to fix them there. + (cond-> (cfh/text-shape? object) + (update :content fix-text-content)))) + + (update-container [container] + (d/update-when container :objects d/update-vals update-shape))] + + (-> data + (update :pages-index d/update-vals update-container) + (d/update-when :components d/update-vals update-container)))) + (def available-migrations (into (d/ordered-set) ["legacy-2" @@ -1667,10 +1669,10 @@ "0004-clean-shadow-color" "0005-deprecate-image-type" "0006-fix-old-texts-fills" - "0007-clear-invalid-strokes-and-fills-v2" "0008-fix-library-colors-v4" "0009-clean-library-colors" "0009-add-partial-text-touched-flags" "0010-fix-swap-slots-pointing-non-existent-shapes" "0011-fix-invalid-text-touched-flags" - "0012-fix-position-data"])) + "0012-fix-position-data" + "0013-clear-invalid-strokes-and-fills"]))