浏览代码

fix: db import after changes from #11433

Gabriel Horner 1 年之前
父节点
当前提交
6093462555

+ 15 - 6
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -269,7 +269,7 @@
                         (and (coll? prop-val) (seq prop-val) (text-with-refs? prop-val prop-val-text))
                         :default
                         (coll? prop-val)
-                        :page
+                        :node
                         :else
                         (db-property-type/infer-property-type-from-value
                          (macro-util/expand-value-if-macro prop-val macros)))
@@ -335,7 +335,7 @@
        (into {})))
 
 (defn- update-page-or-date-values
-  "Converts :page or :date names to entity values"
+  "Converts :node or :date names to entity values"
   [page-names-to-uuids property-values]
   (set (map #(vector :block/uuid
                      ;; assume for now a ref's :block/name can always be translated by lc helper
@@ -358,11 +358,11 @@
       (= :default (:from type-change))
       (or (get properties-text-values prop) (str val))
 
-      ;; treat it the same as a :page
+      ;; treat it the same as a :node
       (= {:from :node :to :date} type-change)
       (update-page-or-date-values page-names-to-uuids val)
 
-      ;; Change to :page as dates can be pages but pages can't be dates
+      ;; Change to :node as dates can be pages but pages can't be dates
       (= {:from :date :to :node} type-change)
       (do
         (swap! property-schemas assoc-in [prop :type] :node)
@@ -835,8 +835,11 @@
 (defn- update-whiteboard-blocks [blocks format]
   (map (fn [b]
          (if (seq (:block/properties b))
-           (update b :block/title #(gp-property/remove-properties format %))
-           b))
+           (-> (dissoc b :block/content)
+               (update :block/title #(gp-property/remove-properties format %)))
+           (cond-> (dissoc b :block/content)
+             (:block/content b)
+             (assoc :block/title (:block/content b)))))
        blocks))
 
 (defn- extract-pages-and-blocks
@@ -854,6 +857,12 @@
 
           (common-config/whiteboard? file)
           (-> (extract/extract-whiteboard-edn file content extract-options')
+              (update :pages (fn [pages]
+                               (->> pages
+                                    ;; migrate previous attribute for :block/title
+                                    (map #(-> %
+                                              (assoc :block/title (:block/original-name %))
+                                              (dissoc :block/original-name))))))
               (update :blocks update-whiteboard-blocks format))
 
           :else

+ 17 - 15
deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

@@ -29,13 +29,15 @@
     (->> content
          (d/q '[:find [(pull ?b [*]) ...]
                 :in $ ?pattern
-                :where [?b :block/title ?content] [(re-find ?pattern ?content)]]
+                :where [?b :block/title ?content]
+                [(missing? $ ?b :block/type)]
+                [(re-find ?pattern ?content)]]
               db)
          first)
     (->> content
          (d/q '[:find [(pull ?b [*]) ...]
                 :in $ ?content
-                :where [?b :block/title ?content]]
+                :where [?b :block/title ?content] [(missing? $ ?b :block/type)]]
               db)
          first)))
 
@@ -202,7 +204,7 @@
                {:db/ident :user.property/prop-string :block/schema {:type :default}}
                {:db/ident :user.property/prop-num :block/schema {:type :number}}
                {:db/ident :user.property/sameas :block/schema {:type :url}}
-               {:db/ident :user.property/rangeincludes :block/schema {:type :page}}
+               {:db/ident :user.property/rangeincludes :block/schema {:type :node}}
                {:db/ident :user.property/startedat :block/schema {:type :date}}}
              (->> @conn
                   (d/q '[:find [(pull ?b [:db/ident :block/schema]) ...]
@@ -293,19 +295,19 @@
           "Collapsed blocks are imported"))
 
     (testing "property :type changes"
-      (is (= :page
+      (is (= :node
              (get-in (d/entity @conn :user.property/finishedat) [:block/schema :type]))
-          ":date property to :page value changes to :page")
-      (is (= :page
+          ":date property to :node value changes to :node")
+      (is (= :node
              (get-in (d/entity @conn :user.property/participants) [:block/schema :type]))
-          ":page property to :date value remains :page")
+          ":node property to :date value remains :node")
 
       (is (= :default
              (get-in (d/entity @conn :user.property/description) [:block/schema :type]))
-          ":default property to :page (or any non :default value) remains :default")
+          ":default property to :node (or any non :default value) remains :default")
       (is (= "[[Jakob]]"
-             (:user.property/description (readable-properties @conn (find-block-by-content @conn #":default to :page"))))
-          ":default to :page property saves :default property value default with full text")
+             (:user.property/description (readable-properties @conn (find-block-by-content @conn #":default to :node"))))
+          ":default to :node property saves :default property value default with full text")
 
       (testing "with changes to upstream/existing property value"
         (is (= :default
@@ -317,13 +319,13 @@
 
         (is (= {:block/schema {:type :default} :db/cardinality :db.cardinality/many}
                (select-keys (d/entity @conn :user.property/people) [:block/schema :db/cardinality]))
-            ":page property to :default value changes to :default and keeps existing cardinality")
+            ":node property to :default value changes to :default and keeps existing cardinality")
         (is (= #{"[[Jakob]] [[Gabriel]]"}
-               (:user.property/people (readable-properties @conn (find-block-by-content @conn ":page people"))))
-            "existing :page property value correctly saved as :default with full text")
+               (:user.property/people (readable-properties @conn (find-block-by-content @conn ":node people"))))
+            "existing :node property value correctly saved as :default with full text")
         (is (= #{"[[Gabriel]] [[Jakob]]"}
-               (:user.property/people (readable-properties @conn (find-block-by-content @conn #"pending block for :page"))))
-            "pending :page property value correctly saved as :default with full text")))
+               (:user.property/people (readable-properties @conn (find-block-by-content @conn #"pending block for :node"))))
+            "pending :node property value correctly saved as :default with full text")))
 
     (testing "replacing refs in :block/title"
       (is (= 2

+ 4 - 4
deps/graph-parser/test/resources/exporter-test-graph/journals/2024_02_16.md

@@ -1,7 +1,7 @@
 - test :dates
   startedAt:: [[Feb 6th, 2024]]
   finishedAt:: [[Feb 7th, 2024]]
-- test :date -> :page
+- test :date -> :node
   finishedAt:: [[Gabriel]]
 - MEETING TITLE
   template:: meeting
@@ -10,9 +10,9 @@
   duration:: 10
 - test :number to :default
   duration:: 20m
-- test :default to :page
+- test :default to :node
   description:: [[Jakob]]
-- test :page -> :date
+- test :node -> :date
   participants:: [[Feb 7th, 2024]]
-- :page people
+- :node people
   people:: [[Jakob]] [[Gabriel]]

+ 2 - 2
deps/graph-parser/test/resources/exporter-test-graph/journals/2024_02_28.md

@@ -1,7 +1,7 @@
 - collapsed block
   collapsed:: true
 	- child
-- pending block for :page to :default
+- pending block for :node to :default
   people:: [[Gabriel]] [[Jakob]]
-- test :page :many to :default
+- test :node :many to :default
   people:: some text