From a7f81ffe47a86ccd85e21efdcf0a8b41f4709175 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 20 Feb 2025 02:04:17 +0800 Subject: [PATCH] fix: add persistent :migrate-new-block-uuid --- deps/common/src/logseq/common/uuid.cljs | 28 +++++++++++++++++------- src/main/frontend/worker/db/migrate.cljs | 7 ++++-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/deps/common/src/logseq/common/uuid.cljs b/deps/common/src/logseq/common/uuid.cljs index 3c4406d0e2..d359d5da61 100644 --- a/deps/common/src/logseq/common/uuid.cljs +++ b/deps/common/src/logseq/common/uuid.cljs @@ -19,23 +19,35 @@ the remaining chars for data of this type" (let [s-length (count s)] (apply str s (repeat (- length s-length) "0")))) -(defn- gen-db-ident-block-uuid - "00000002--" - [db-ident] - {:pre [(keyword? db-ident)]} - (let [hash-num (str (Math/abs (hash db-ident))) +(defn gen-block-uuid + "prefix--" + [key prefix] + {:pre [(keyword? key)]} + (let [hash-num (str (Math/abs (hash key))) part1 (fill-with-0 (subs hash-num 0 4) 4) part2 (fill-with-0 (subs hash-num 4 8) 4) part3 (fill-with-0 (subs hash-num 8 12) 4) part4 (fill-with-0 (subs hash-num 12) 12)] - (uuid (str "00000002-" part1 "-" part2 "-" part3 "-" part4)))) + (uuid (str prefix "-" part1 "-" part2 "-" part3 "-" part4)))) + +(defn- gen-db-ident-block-uuid + "00000002--" + [db-ident] + {:pre [(keyword? db-ident)]} + (gen-block-uuid db-ident "00000002")) + +;; 00000001 journal +;; 00000002 db ident +;; 00000003 new blocks created by migration (defn gen-uuid "supported type: - :journal-page-uuid - - :db-ident-block-uuid" + - :db-ident-block-uuid + - :migrate-new-block-uuid" ([] (d/squuid)) ([type' v] (case type' :journal-page-uuid (gen-journal-page-uuid v) - :db-ident-block-uuid (gen-db-ident-block-uuid v)))) + :db-ident-block-uuid (gen-db-ident-block-uuid v) + :migrate-new-block-uuid (gen-block-uuid v "00000003")))) diff --git a/src/main/frontend/worker/db/migrate.cljs b/src/main/frontend/worker/db/migrate.cljs index 4be1b70d7e..814ee4de36 100644 --- a/src/main/frontend/worker/db/migrate.cljs +++ b/src/main/frontend/worker/db/migrate.cljs @@ -636,8 +636,11 @@ (let [view-page-id (:db/id (ldb/get-page db common-config/views-page-name)) _ (when (nil? view-page-id) (throw (ex-info "View page not exists" {}))) - view (-> (assoc view-properties :logseq.property/view-for id) - (merge {:block/uuid (common-uuid/gen-uuid) + view (-> view-properties + (merge {:logseq.property/view-for id + :block/uuid (common-uuid/gen-uuid :migrate-new-block-uuid + (keyword "temp-view-for" + (string/replace (str (:block/uuid e)) "-" ""))) :block/title "All" :block/parent view-page-id :block/page view-page-id