From 3334fb0e99f83213b70caad4514036149255ebc4 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 2 Nov 2024 09:57:53 +0100 Subject: [PATCH] :bug: Add migration to fix invalid pages --- common/src/app/common/files/changes.cljc | 2 +- common/src/app/common/files/defaults.cljc | 2 +- common/src/app/common/files/migrations.cljc | 32 ++++++++++++++++++++- common/src/app/common/geom/point.cljc | 3 ++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 3c097b5d0c..1ff501f345 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -467,7 +467,7 @@ #?(:clj (validate-shapes! data result items)) result)))) -;; DEPRECATED: remove before 2.3 release +;; DEPRECATED: remove after 2.3 release (defmethod process-change :set-option [data _] data) diff --git a/common/src/app/common/files/defaults.cljc b/common/src/app/common/files/defaults.cljc index 7628d9469e..21a8f304f3 100644 --- a/common/src/app/common/files/defaults.cljc +++ b/common/src/app/common/files/defaults.cljc @@ -6,4 +6,4 @@ (ns app.common.files.defaults) -(def version 56) +(def version 57) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index a2e2b5f55a..2ac80c1de0 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -13,6 +13,7 @@ [app.common.files.defaults :as cfd] [app.common.files.helpers :as cfh] [app.common.geom.matrix :as gmt] + [app.common.geom.point :as gpt] [app.common.geom.rect :as grc] [app.common.geom.shapes :as gsh] [app.common.geom.shapes.path :as gsp] @@ -1102,6 +1103,33 @@ (update :pages-index update-vals update-container) (update :components update-vals update-container)))) + +(defn migrate-up-57 + [data] + (letfn [(fix-thread-positions [positions] + (reduce-kv (fn [result id {:keys [position] :as data}] + (let [data (cond + (gpt/point? position) + data + + (and (map? position) + (gpt/valid-point-attrs? position)) + (assoc data :position (gpt/point position)) + + :else + (assoc data :position (gpt/point 0 0)))] + (assoc result id data))) + positions + positions)) + + (update-page [page] + (d/update-when page :comment-thread-positions fix-thread-positions))] + + (-> data + (update :pages (fn [pages] (into [] (remove nil?) pages))) + (update :pages-index dissoc nil) + (update :pages-index update-vals update-page)))) + (def migrations "A vector of all applicable migrations" [{:id 2 :migrate-up migrate-up-2} @@ -1149,4 +1177,6 @@ {:id 53 :migrate-up migrate-up-26} {:id 54 :migrate-up migrate-up-54} {:id 55 :migrate-up migrate-up-55} - {:id 56 :migrate-up migrate-up-56}]) + {:id 56 :migrate-up migrate-up-56} + {:id 57 :migrate-up migrate-up-57}]) + diff --git a/common/src/app/common/geom/point.cljc b/common/src/app/common/geom/point.cljc index 2ac57cdbc3..3e6a4c727f 100644 --- a/common/src/app/common/geom/point.cljc +++ b/common/src/app/common/geom/point.cljc @@ -56,6 +56,9 @@ [:x ::sm/safe-number] [:y ::sm/safe-number]]) +(def valid-point-attrs? + (sm/validator schema:point-attrs)) + (def valid-point? (sm/validator [:and [:fn point?] schema:point-attrs]))