fix: db errors

This commit is contained in:
Tienson Qin
2022-05-31 21:53:58 +08:00
parent e94b86aadc
commit 6fe6f76ab9

View File

@@ -82,19 +82,20 @@
(defn- replace-db-id-with-block-uuid
[tx-report block]
(walk/postwalk (fn [f]
(if (and (map? f)
(= 1 (count f))
(:db/id f))
(let [block-uuid (or (:block/uuid (d/entity (:db-before tx-report) (:db/id f)))
(:block/uuid (d/entity (:db-after tx-report) (:db/id f))))]
(if block-uuid
[:block/uuid block-uuid]
(throw (ex-info "Can't resolve entity in both db-before and db-after"
{:block block
:f f}))))
f))
block))
(let [block (dissoc block :block/file)]
(walk/postwalk (fn [f]
(if (and (map? f)
(= 1 (count f))
(:db/id f))
(let [block-uuid (or (:block/uuid (d/entity (:db-before tx-report) (:db/id f)))
(:block/uuid (d/entity (:db-after tx-report) (:db/id f))))]
(if block-uuid
[:block/uuid block-uuid]
(throw (ex-info "Can't resolve entity in both db-before and db-after"
{:block block
:f f}))))
f))
block)))
;; TODO: merge pages, page names are same but with different uuids
(defn- transact-blocks!