Bläddra i källkod

fix: more import fixes after testing more graphs

- collapsed:: false was failing an import
- ignore more attributes for existing pages
- also fixed import script not handling macros and absolute paths
  correctly
Gabriel Horner 1 år sedan
förälder
incheckning
0b0299b28f

+ 20 - 17
deps/graph-parser/script/db_import.cljs

@@ -37,6 +37,14 @@
   (p/let [s (fsp/readFile (:rpath file))]
     (str s)))
 
+(defn- build-import-options [conn config options]
+  (-> (gp-exporter/setup-import-options
+       @conn
+       {}
+       (select-keys options [:tag-classes :property-classes])
+       {:notify-user prn :macros (:macros config)})
+      (assoc-in [:extract-options :verbose] (:verbose options))))
+
 (defn- import-file-graph-to-db [file-graph-dir conn options]
   (p/let [*files (build-graph-files file-graph-dir)
           config-file (first (filter #(string/ends-with? (:rpath %) "logseq/config.edn") *files))
@@ -44,12 +52,7 @@
           ;; TODO: Add :default-config option
           config (gp-exporter/import-config-file! conn config-file <read-file {:notify-user prn})
           files (remove-hidden-files file-graph-dir config *files)
-          import-options (-> (gp-exporter/setup-import-options
-                            @conn
-                            {}
-                            (select-keys options [:tag-classes :property-classes])
-                            {:notify-user prn})
-                           (assoc-in [:extract-options :verbose] (:verbose options)))
+          import-options (build-import-options conn config options)
           logseq-file? #(string/includes? (:rpath %) "logseq/")
           doc-files (remove logseq-file? files)
           logseq-files (filter logseq-file? files)]
@@ -58,16 +61,17 @@
      (gp-exporter/import-logseq-files conn logseq-files <read-file {:notify-user prn})
      (gp-exporter/import-from-doc-files! conn doc-files <read-file import-options))))
 
+(defn- resolve-path
+  "If relative path, resolve with $ORIGINAL_PWD"
+  [path]
+  (if (node-path/isAbsolute path)
+    path
+    (node-path/join (or js/process.env.ORIGINAL_PWD ".") path)))
+
 (defn- import-files-to-db [file conn {:keys [files] :as options}]
-  (let [import-options (-> (gp-exporter/setup-import-options
-                            @conn
-                            {}
-                            (select-keys options [:tag-classes :property-classes])
-                            {:notify-user prn})
-                           (assoc-in [:extract-options :verbose] (:verbose options)))
+  (let [import-options (build-import-options conn {:macros {}} options)
         files' (mapv #(hash-map :rpath %)
-                     (into [file]
-                           (map #(node-path/join (or js/process.env.ORIGINAL_PWD ".") %) files)))]
+                     (into [file] (map resolve-path files)))]
     (gp-exporter/import-from-doc-files! conn files' <read-file import-options)))
 
 (def spec
@@ -94,11 +98,10 @@
                           (cli/format-opts {:spec spec})))
             (js/process.exit 1))
         [dir db-name] (if (string/includes? db-graph-dir "/")
-                        (let [graph-dir'
-                              (node-path/join (or js/process.env.ORIGINAL_PWD ".") db-graph-dir)]
+                        (let [graph-dir' (resolve-path db-graph-dir)]
                           ((juxt node-path/dirname node-path/basename) graph-dir'))
                         [(node-path/join (os/homedir) "logseq" "graphs") db-graph-dir])
-        file-graph' (node-path/join (or js/process.env.ORIGINAL_PWD ".") file-graph)
+        file-graph' (resolve-path file-graph)
         conn (create-graph/init-conn dir db-name)
         directory? (.isDirectory (fs/statSync file-graph'))]
     (p/do!

+ 4 - 2
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -96,7 +96,7 @@
 (def ignored-built-in-properties
   "Ignore built-in properties that are already imported or not supported in db graphs"
   ;; Already imported via a datascript attribute i.e. have :attribute on property config
-  [:tags :alias
+  [:tags :alias :collapsed
    ;; Not supported as they have been ignored for a long time and cause invalid built-in pages
    :now :later :doing :done :canceled :cancelled :in-progress :todo :wait :waiting])
 
@@ -446,7 +446,9 @@
         pages-tx (keep #(if (existing-page-names (:block/name %))
                           (let [schema (get new-property-schemas (keyword (:block/name %)))
                                 ;; These attributes are not allowed to be transacted because they must not change across files
-                                disallowed-attributes [:block/name :block/uuid :block/format :block/journal? :block/original-name :block/journal-day]
+                                ;; block/uuid was particularly bad as it actually changed the page's identity across files
+                                disallowed-attributes [:block/name :block/uuid :block/format :block/journal? :block/original-name :block/journal-day
+                                                       :block/type :block/created-at :block/updated-at]
                                 allowed-attributes [:block/properties :block/tags :block/alias :block/namespace]
                                 block-changes (select-keys % allowed-attributes)]
                             (when-let [ignored-attrs (not-empty (apply dissoc % (into disallowed-attributes allowed-attributes)))]