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:
Gabriel Horner
2025-12-04 10:13:30 -05:00
parent c8f99d1ff3
commit 8fc56bfaa3
8 changed files with 69 additions and 84 deletions

View File

@@ -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*))