Skip to content

Commit

Permalink
🐛 Add migration to remove all misplaced slots
Browse files Browse the repository at this point in the history
  • Loading branch information
hirunatan committed Jun 3, 2024
1 parent b700a92 commit 21052c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common/src/app/common/files/defaults.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

(ns app.common.files.defaults)

(def version 47)
(def version 48)
17 changes: 16 additions & 1 deletion common/src/app/common/files/migrations.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,20 @@
(-> data
(update :pages-index update-vals update-page))))

(defn migrate-up-48
[data]
(letfn [(fix-shape [shape]
(let [swap-slot (ctk/get-swap-slot shape)]
(if (and (some? swap-slot)
(not (ctk/subcopy-head? shape)))
(ctk/remove-swap-slot shape)
shape)))

(update-page [page]
(d/update-when page :objects update-vals fix-shape))]
(-> data
(update :pages-index update-vals update-page))))

(def migrations
"A vector of all applicable migrations"
[{:id 2 :migrate-up migrate-up-2}
Expand Down Expand Up @@ -961,4 +975,5 @@
{:id 44 :migrate-up migrate-up-44}
{:id 45 :migrate-up migrate-up-45}
{:id 46 :migrate-up migrate-up-46}
{:id 47 :migrate-up migrate-up-47}])
{:id 47 :migrate-up migrate-up-47}
{:id 48 :migrate-up migrate-up-48}])
10 changes: 9 additions & 1 deletion common/src/app/common/types/component.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@
(and (some? (:component-id shape))
(nil? (:component-root shape))))

(defn subcopy-head?
"Check if this shape is the head of a subinstance that is a copy."
[shape]
;; This is redundant with the previous one, but may give more security
;; in case of bugs.
(and (some? (:component-id shape))
(nil? (:component-root shape))
(some? (:shape-ref shape))))

(defn instance-of?
[shape file-id component-id]
(and (some? (:component-id shape))
Expand Down Expand Up @@ -227,7 +236,6 @@
:shape-ref
:touched))


(defn- extract-ids [shape]
(if (map? shape)
(let [current-id (:id shape)
Expand Down

0 comments on commit 21052c6

Please sign in to comment.