fix: migration

This commit is contained in:
Tienson Qin
2024-12-03 14:20:31 +08:00
parent c428b87dce
commit 4e9d071fa0
5 changed files with 34 additions and 30 deletions

View File

@@ -7,14 +7,12 @@
(def ^:large-vars/data-var built-in-classes
"Map of built-in classes for db graphs with their :db/ident as keys"
(ordered-map
:logseq.class/Tag {:title "Tag"}
:logseq.class/Root {:title "Root Tag"}
:logseq.class/Page {:title "Page"}
:logseq.class/Tag
{:title "Tag"
:properties {:block/tags :logseq.class/Page}}
:logseq.class/Whiteboard
{:title "Whiteboard"
:properties {:block/tags :logseq.class/Page}}

View File

@@ -111,7 +111,9 @@
(dissoc schema
:block/namespace :block/properties-text-values :block/pre-block? :recent/pages :block/file
:block/properties :block/properties-order :block/repeated? :block/deadline :block/scheduled :block/priority
:block/marker :block/macros :block/type)
:block/marker :block/macros
;; :block/type
)
{:block/name {:db/index true} ; remove db/unique for :block/name
;; closed value
:block/closed-value-property {:db/valueType :db.type/ref

View File

@@ -115,8 +115,10 @@
{:pre [(qualified-keyword? (:db/ident block))]}
(block-with-timestamps
(cond-> (merge block
{:block/tags #{:logseq.class/Tag}
:block/format :markdown})
(cond->
{:block/format :markdown}
(not= (:db/ident block) :logseq.class/Tag)
(assoc :block/tags #{:logseq.class/Tag})))
(and (not= (:db/ident block) :logseq.class/Root)
(nil? (:logseq.property/parent block)))
(assoc :logseq.property/parent :logseq.class/Root))))

View File

@@ -32,16 +32,16 @@
(throw e)))))
(defn add-tag [repo block-id tag-entity]
(ui-outliner-tx/transact!
{:outliner-op :save-block}
(p/do!
(editor-handler/save-current-block!)
(let [opts {:outliner-op :save-block}]
(ui-outliner-tx/transact! opts
(p/do!
(editor-handler/save-current-block!)
;; Check after save-current-block to get most up to date block content
(when (valid-tag? repo (db/entity repo [:block/uuid block-id]) tag-entity)
(let [tx-data [[:db/add [:block/uuid block-id] :block/tags (:db/id tag-entity)]
(when (valid-tag? repo (db/entity repo [:block/uuid block-id]) tag-entity)
(let [tx-data [[:db/add [:block/uuid block-id] :block/tags (:db/id tag-entity)]
;; TODO: Move this to outliner.core to consistently add refs for tags
[:db/add [:block/uuid block-id] :block/refs (:db/id tag-entity)]]]
(db/transact! repo tx-data {:outliner-op :save-block}))))))
[:db/add [:block/uuid block-id] :block/refs (:db/id tag-entity)]]]
(db/transact! repo tx-data {:outliner-op :save-block})))))))
(defn convert-to-tag!
[page-entity]

View File

@@ -420,23 +420,25 @@
(defn- replace-block-type-with-tags
[conn _search-db]
(let [db @conn
datoms (d/datoms db :block/type)
block-type-entity (d/entity db :block/type)
datoms (d/datoms db :avet :block/type)
journal-entity (d/entity db :logseq.class/Journal)
tx-data (map (fn [{:keys [e _a v]}]
(let [tag (case v
"page" :logseq.class/Page
"class" :logseq.class/Tag
"property" :logseq.class/Property
"journal" :logseq.class/Journal
"whiteboard" :logseq.class/Whiteboard
"closed value" :logseq.class/Closed-Value
(throw (ex-info "unsupported block/type" {:type v})))]
[[:db/retract e :block/type]
[:db/add e :block/tags tag]])) datoms)]
tx-data (mapcat (fn [{:keys [e _a v]}]
(let [tag (case v
"page" :logseq.class/Page
"class" :logseq.class/Tag
"property" :logseq.class/Property
"journal" :logseq.class/Journal
"whiteboard" :logseq.class/Whiteboard
"closed value" :logseq.class/Closed-Value
(throw (ex-info "unsupported block/type" {:type v})))]
[[:db/retract e :block/type]
[:db/add e :block/tags tag]])) datoms)]
(concat
;; set journal's parent to `#Page`
[[:db/add (:db/id journal-entity) :logseq.property/parent :logseq.class/Page]]
tx-data)))
;; set journal's tag to `#Page`
[[:db/add (:db/id journal-entity) :block/tags :logseq.class/Page]]
tx-data
[[:db/retractEntity (:db/id block-type-entity)]])))
(def schema-version->updates
"A vec of tuples defining datascript migrations. Each tuple consists of the