mirror of
https://github.com/logseq/logseq.git
synced 2026-04-27 23:54:55 +00:00
enhance(dev): scripts can read or write db graphs as full path files
This allows for easier use of debugging graphs as they are exported by users as a file. Also DRYed up duplicated helper
This commit is contained in:
21
deps/db/script/validate_db.cljs
vendored
21
deps/db/script/validate_db.cljs
vendored
@@ -1,11 +1,8 @@
|
||||
(ns validate-db
|
||||
"Script that validates the datascript db of a DB graph
|
||||
NOTE: This script is also used in CI to confirm our db's schema is up to date"
|
||||
(:require ["os" :as os]
|
||||
["path" :as node-path]
|
||||
[babashka.cli :as cli]
|
||||
(:require [babashka.cli :as cli]
|
||||
[cljs.pprint :as pprint]
|
||||
[clojure.string :as string]
|
||||
[datascript.core :as d]
|
||||
[logseq.db.frontend.malli-schema :as db-malli-schema]
|
||||
[logseq.db.frontend.validate :as db-validate]
|
||||
@@ -50,17 +47,6 @@
|
||||
(js/process.exit 1))
|
||||
(println "Valid!"))))
|
||||
|
||||
(defn- get-dir-and-db-name
|
||||
"Gets dir and db name for use with open-db! Works for relative and absolute paths and
|
||||
defaults to ~/logseq/graphs/ when no '/' present in name"
|
||||
[graph-dir]
|
||||
(if (string/includes? graph-dir "/")
|
||||
(let [resolve-path' #(if (node-path/isAbsolute %) %
|
||||
;; $ORIGINAL_PWD used by bb tasks to correct current dir
|
||||
(node-path/join (or js/process.env.ORIGINAL_PWD ".") %))]
|
||||
((juxt node-path/dirname node-path/basename) (resolve-path' graph-dir)))
|
||||
[(node-path/join (os/homedir) "logseq" "graphs") graph-dir]))
|
||||
|
||||
(def spec
|
||||
"Options spec"
|
||||
{:help {:alias :h
|
||||
@@ -86,8 +72,9 @@
|
||||
(validate-db* db ent-maps options)))
|
||||
|
||||
(defn- validate-graph [graph-dir options]
|
||||
(let [[dir db-name] (get-dir-and-db-name graph-dir)
|
||||
conn (try (sqlite-cli/open-db! dir db-name)
|
||||
(let [open-db-args (sqlite-cli/->open-db-args graph-dir)
|
||||
db-name (if (= 1 (count open-db-args)) (first open-db-args) (second open-db-args))
|
||||
conn (try (apply sqlite-cli/open-db! open-db-args)
|
||||
(catch :default e
|
||||
(println "Error: For graph" (str (pr-str graph-dir) ":") (str e))
|
||||
(js/process.exit 1)))]
|
||||
|
||||
Reference in New Issue
Block a user