Improve migrate-data function (file data migrations)

This will enable the ability to apply some migration to a specific
file from the Server REPL.
This commit is contained in:
Andrey Antukh 2022-03-30 15:31:12 +02:00 committed by Andrés Moya
parent 59d0bafdc9
commit 13ca506015
2 changed files with 10 additions and 12 deletions

View file

@ -10,6 +10,7 @@
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.geom.shapes.path :as gsp] [app.common.geom.shapes.path :as gsp]
[app.common.logging :as l]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
@ -21,17 +22,14 @@
(defmulti migrate :version) (defmulti migrate :version)
(defn migrate-data (defn migrate-data
([data] ([data] (migrate-data data cp/file-version))
(if (= (:version data) cp/file-version) ([data to-version]
(if (= (:version data) to-version)
data data
(reduce #(migrate-data %1 %2 (inc %2)) (let [migrate-fn #(do
data (l/trace :hint "migrate file" :id (:id %) :version-from %2 :version-to (inc %2))
(range (:version data 0) cp/file-version)))) (migrate (assoc %1 :version (inc %2))))]
(reduce migrate-fn data (range (:version data 0) to-version))))))
([data _ to-version]
(-> data
(assoc :version to-version)
(migrate))))
(defn migrate-file (defn migrate-file
[file] [file]

View file

@ -38,7 +38,7 @@
:components {} :components {}
:version 7} :version 7}
res (cpm/migrate-data data nil 8)] res (cpm/migrate-data data 8)]
;; (pprint data) ;; (pprint data)
;; (pprint res) ;; (pprint res)
@ -81,7 +81,7 @@
(let [id (uuid/custom 1 2)] (let [id (uuid/custom 1 2)]
(into [] (remove #(= id %)) shapes))))) (into [] (remove #(= id %)) shapes)))))
res (cpm/migrate-data data nil 8)] res (cpm/migrate-data data 8)]
;; (pprint res) ;; (pprint res)
;; (pprint expect) ;; (pprint expect)