mirror of
https://github.com/logseq/logseq.git
synced 2026-04-29 00:24:51 +00:00
refactor: Update importer to use validate-local-db
Also update validation in DB scripts: * replace alternative validate-db impl with standard CLI one * Add validation to import script * Choose to decouple other DB scripts from validate-db as it may go away later
This commit is contained in:
20
deps/db/script/create_graph.cljs
vendored
20
deps/db/script/create_graph.cljs
vendored
@@ -7,11 +7,12 @@
|
||||
[clojure.edn :as edn]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.db.common.sqlite-cli :as sqlite-cli]
|
||||
[logseq.db.frontend.validate :as db-validate]
|
||||
[logseq.db.sqlite.export :as sqlite-export]
|
||||
[logseq.outliner.cli :as outliner-cli]
|
||||
[clojure.pprint :as pprint]
|
||||
[nbb.classpath :as cp]
|
||||
[nbb.core :as nbb]
|
||||
[validate-db]))
|
||||
[nbb.core :as nbb]))
|
||||
|
||||
(defn- resolve-path
|
||||
"If relative path, resolve with $ORIGINAL_PWD"
|
||||
@@ -20,6 +21,19 @@
|
||||
path
|
||||
(node-path/join (or js/process.env.ORIGINAL_PWD ".") path)))
|
||||
|
||||
(defn- validate-db [db db-name options]
|
||||
(if-let [errors (:errors
|
||||
(db-validate/validate-local-db!
|
||||
db
|
||||
(merge options {:db-name db-name :verbose true})))]
|
||||
(do
|
||||
(println "Found" (count errors)
|
||||
(if (= 1 (count errors)) "entity" "entities")
|
||||
"with errors:")
|
||||
(pprint/pprint errors)
|
||||
(js/process.exit 1))
|
||||
(println "Valid!")))
|
||||
|
||||
(def spec
|
||||
"Options spec"
|
||||
{:help {:alias :h
|
||||
@@ -56,7 +70,7 @@
|
||||
(when (seq misc-tx) (ldb/transact! conn misc-tx))
|
||||
(println (if graph-exists? "Updated graph" "Created graph") (str db-name "!"))
|
||||
(when (:validate options)
|
||||
(validate-db/validate-db @conn db-name {:group-errors true :closed-maps true :humanize true}))))
|
||||
(validate-db @conn db-name {}))))
|
||||
|
||||
(when (= nbb/*file* (nbb/invoked-file))
|
||||
(-main *command-line-args*))
|
||||
|
||||
Reference in New Issue
Block a user