From 7f2e819789ff3f93359c3c4a30d98031b5177b5c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 25 Jun 2025 13:20:12 +0200 Subject: [PATCH 1/3] :bug: Fix migration persistence ordering issue When migrations are applied to old files --- common/src/app/common/files/migrations.cljc | 43 +++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index aa56dbe65d..02b43cbd14 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -94,22 +94,33 @@ (defn migrate-file [file libs] (binding [cfeat/*new* (atom #{})] - (let [version (or (:version file) - (-> file :data :version))] - (-> file - (assoc :version cfd/version) - (update :migrations - (fn [migrations] - (if (nil? migrations) - (generate-migrations-from-version version) - migrations))) - ;; NOTE: in some future we can consider to apply - ;; a migration to the whole database and remove - ;; this code from this function that executes on - ;; each file migration operation - (update :features cfeat/migrate-legacy-features) - (migrate libs) - (update :features (fnil into #{}) (deref cfeat/*new*)))))) + (let [version + (or (:version file) (-> file :data :version)) + + migrations + (not-empty (get file :migrations)) + + file + (-> file + (assoc :version cfd/version) + (assoc :migrations + (if migrations + migrations + (generate-migrations-from-version version))) + ;; NOTE: in some future we can consider to apply a + ;; migration to the whole database and remove this code + ;; from this function that executes on each file + ;; migration operation + (update :features cfeat/migrate-legacy-features) + (migrate libs) + (update :features (fnil into #{}) (deref cfeat/*new*)))] + + ;; NOTE: When we have no previous migrations, we report all + ;; migrations as migrated in order to correctly persist them all + ;; and not only the really applied migrations + (if (not migrations) + (vary-meta file assoc ::migrated (:migrations file)) + file)))) (defn migrated? [file] From 15c91a5de58b9b11f2a8d40201b5c3f6b9811dd6 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 25 Jun 2025 13:26:32 +0200 Subject: [PATCH 2/3] :sparkles: Make the bool-content normalize migration idempotent --- common/src/app/common/files/migrations.cljc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 02b43cbd14..3cad118502 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1284,7 +1284,8 @@ ;; rollback, we still need to perform an other migration ;; for properly delete the bool-content prop from shapes ;; once the know the migration was OK - (if (cfh/bool-shape? object) + (if (and (cfh/bool-shape? object) + (not (contains? object :content))) (if-let [content (:bool-content object)] (assoc object :content content) object) From 93cbd999322cb764b2f50a34dbef1d7c3e9d62f7 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 25 Jun 2025 13:26:56 +0200 Subject: [PATCH 3/3] :bug: Clear invalid keys from color libraries --- common/src/app/common/files/migrations.cljc | 5 +++-- common/src/app/common/types/color.cljc | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 3cad118502..0c18ea7ad8 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1480,7 +1480,7 @@ (update :pages-index d/update-vals update-container) (d/update-when :components d/update-vals update-container)))) -(defmethod migrate-data "0008-fix-library-colors" +(defmethod migrate-data "0008-fix-library-colors-v2" [data _] (letfn [(clear-color-opacity [color] (if (and (contains? color :opacity) @@ -1490,6 +1490,7 @@ (clear-color [color] (-> color + (select-keys types.color/library-color-attrs) (d/without-nils) (d/without-qualified) (clear-color-opacity)))] @@ -1559,4 +1560,4 @@ "0005-deprecate-image-type" "0006-fix-old-texts-fills" "0007-clear-invalid-strokes-and-fills-v2" - "0008-fix-library-colors"])) + "0008-fix-library-colors-v2"])) diff --git a/common/src/app/common/types/color.cljc b/common/src/app/common/types/color.cljc index 89b84ea1e9..6b3893d3ef 100644 --- a/common/src/app/common/types/color.cljc +++ b/common/src/app/common/types/color.cljc @@ -150,6 +150,9 @@ (sm/optional-keys schema:image-color)] [:fn has-valid-color-attrs?]]) +(def library-color-attrs + (sm/keys schema:library-color-attrs)) + (def valid-color? (sm/lazy-validator schema:color))