From 1ffdb41cfc7954ad34db3f68c22d9424a48ad6e0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 13 Nov 2020 14:47:34 +0100 Subject: [PATCH] :bug: Add data migration for ensure proper types on group like shapes. Becuse of a bug, the `:shapes` attribute on group like objects had become to seq when they should be a vector. The real fix is already in other commit. This commit adds a migration for address the old data already stored in the database. --- common/app/common/pages.cljc | 6 ++--- common/app/common/pages_migrations.cljc | 29 +++++++++++-------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/common/app/common/pages.cljc b/common/app/common/pages.cljc index bb92b63ea..b46f12ed4 100644 --- a/common/app/common/pages.cljc +++ b/common/app/common/pages.cljc @@ -20,7 +20,7 @@ [app.common.spec :as us] [app.common.uuid :as uuid])) -(def file-version 1) +(def file-version 2) (def max-safe-int 9007199254740991) (def min-safe-int -9007199254740991) @@ -268,7 +268,7 @@ (s/every :internal.shape/point :kind vector?)) (s/def :internal.shape/shapes - (s/every uuid?)) + (s/every uuid? :kind vector?)) (s/def ::shape-attrs (s/keys :opt-un [:internal.shape/blocked @@ -295,7 +295,7 @@ :internal.shape/x :internal.shape/y :internal.shape/exports - ;; :internal.shape/shapes + :internal.shape/shapes :internal.shape/stroke-color :internal.shape/stroke-color-ref-file :internal.shape/stroke-color-ref-id diff --git a/common/app/common/pages_migrations.cljc b/common/app/common/pages_migrations.cljc index 33171c9fb..7d9b89bc0 100644 --- a/common/app/common/pages_migrations.cljc +++ b/common/app/common/pages_migrations.cljc @@ -34,21 +34,18 @@ ;; -- MIGRATIONS -- -(defn- generate-child-parent-index - [objects] - (reduce-kv - (fn [index id obj] - (into index (map #(vector % id) (:shapes obj [])))) - {} objects)) +;; Ensure that all :shape attributes on shapes are vectors. -;; (defmethod migrate 5 -;; [data] -;; (update data :objects -;; (fn [objects] -;; (let [index (generate-child-parent-index objects)] -;; (d/mapm -;; (fn [id obj] -;; (let [parent-id (get index id)] -;; (assoc obj :parent-id parent-id))) -;; objects))))) +(defmethod migrate 2 + [data] + (letfn [(update-object [id object] + (d/update-when object :shapes + (fn [shapes] + (if (seq? shapes) + (into [] shapes) + shapes)))) + (update-page [id page] + (update page :objects #(d/mapm update-object %)))] + + (update data :pages-index #(d/mapm update-page %))))