Kaynağa Gözat

chore: remove db scripts made redundant by CLI

Gabriel Horner 1 hafta önce
ebeveyn
işleme
ef96a8d031

+ 3 - 2
.github/workflows/build.yml

@@ -172,11 +172,12 @@ jobs:
       - name: Fetch deps/db yarn deps
         run: cd deps/db && yarn install --frozen-lockfile
 
+      # Can run from deps/db since all JS deps for this command are available in deps/db
       - name: Validate created DB graphs
-        run: cd deps/db && yarn nbb-logseq script/validate_db.cljs ../../scripts/properties-graph ../../scripts/schema-graph --closed-maps --group-errors
+        run: cd deps/db && yarn nbb-logseq -cp src:../cli/src -m logseq.cli validate -g ../../scripts/schema-graph
 
       - name: Export a created DB graph
-        run: cd deps/db && yarn nbb-logseq script/export_graph.cljs ../../scripts/properties-graph -f properties.edn -T
+        run: cd deps/db && yarn nbb-logseq -cp src:../cli/src -m logseq.cli export-edn -g ../../scripts/properties-graph -f properties.edn -T
 
       - name: Create graph from the export and diff the two graphs
         run: cd deps/db && yarn nbb-logseq -cp src:../outliner/src:script script/create_graph.cljs ./properties-graph2 properties.edn -iv && yarn nbb-logseq script/diff_graphs.cljs ../../scripts/properties-graph ./properties-graph2 -T

+ 0 - 13
bb.edn

@@ -67,13 +67,6 @@
            (run '-dev:publishing-dev {:parallel true})
            (run '-dev:publishing-release))}
 
-  dev:validate-db
-  {:doc "Validate a DB graph's datascript schema"
-   :requires ([babashka.fs :as fs])
-   :task (apply shell {:dir "deps/db" :extra-env {"ORIGINAL_PWD" (fs/cwd)}}
-                "yarn -s nbb-logseq script/validate_db.cljs"
-                *command-line-args*)}
-
   dev:db-query
   {:doc "Query a DB graph's datascript db"
    :requires ([babashka.fs :as fs])
@@ -92,12 +85,6 @@
    :task (apply shell {:dir "deps/db" :extra-env {"ORIGINAL_PWD" (fs/cwd)}}
                 "yarn -s nbb-logseq -cp src:../outliner/src:script script/create_graph.cljs" *command-line-args*)}
 
-  dev:db-export
-  {:doc "Export a DB graph to a sqlite.build EDN file"
-   :requires ([babashka.fs :as fs])
-   :task (apply shell {:dir "deps/db" :extra-env {"ORIGINAL_PWD" (fs/cwd)}}
-                "yarn -s nbb-logseq script/export_graph.cljs" *command-line-args*)}
-
   dev:db-diff
   {:doc "Diffs two DB graphs"
    :requires ([babashka.fs :as fs])

+ 0 - 62
deps/db/script/export_graph.cljs

@@ -1,62 +0,0 @@
-(ns export-graph
-  "A script that exports a graph to a sqlite.build EDN file"
-  (:require ["fs" :as fs]
-            ["path" :as node-path]
-            [babashka.cli :as cli]
-            [clojure.pprint :as pprint]
-            [logseq.db.common.sqlite-cli :as sqlite-cli]
-            [logseq.db.sqlite.export :as sqlite-export]
-            [nbb.core :as nbb]))
-
-(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)))
-
-(def spec
-  "Options spec"
-  {:help {:alias :h
-          :desc "Print help"}
-   :include-timestamps? {:alias :T
-                         :desc "Include timestamps in export"}
-   :file {:alias :f
-          :desc "Saves edn to file"}
-   :catch-validation-errors? {:alias :c
-                              :desc "Catch validation errors for dev"}
-   :exclude-namespaces {:alias :e
-                        :coerce #{}
-                        :desc "Namespaces to exclude from properties and classes"}
-   :exclude-built-in-pages? {:alias :b
-                             :desc "Exclude built-in pages"}
-   :exclude-files? {:alias :F
-                    :desc "Exclude :file/path files"}
-   :export-type {:alias :t
-                 :coerce :keyword
-                 :desc "Export type"
-                 :default :graph}})
-
-(defn -main [args]
-  (let [{options :opts args' :args} (cli/parse-args args {:spec spec})
-        graph-dir (first args')
-        _ (when (or (nil? graph-dir) (:help options))
-            (println (str "Usage: $0 GRAPH-NAME [& ARGS] [OPTIONS]\nOptions:\n"
-                          (cli/format-opts {:spec spec})))
-            (js/process.exit 1))
-        conn (apply sqlite-cli/open-db! (sqlite-cli/->open-db-args graph-dir))
-        export-map (sqlite-export/build-export @conn
-                                               (cond-> {:export-type (:export-type options)}
-                                                 (= :graph (:export-type options))
-                                                 (assoc :graph-options (dissoc options :file :export-type))))]
-    (if (:file options)
-      (do
-        (println "Exported" (count (:properties export-map)) "properties,"
-                 (count (:properties export-map)) "classes and"
-                 (count (:pages-and-blocks export-map)) "pages")
-        (fs/writeFileSync (resolve-path (:file options))
-                          (with-out-str (pprint/pprint export-map))))
-      (pprint/pprint export-map))))
-
-(when (= nbb/*file* (nbb/invoked-file))
-  (-main *command-line-args*))

+ 0 - 51
deps/db/script/validate_db.cljs

@@ -1,51 +0,0 @@
-(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 [babashka.cli :as cli]
-            [cljs.pprint :as pprint]
-            [datascript.core :as d]
-            [logseq.db.common.sqlite-cli :as sqlite-cli]
-            [logseq.db.frontend.malli-schema :as db-malli-schema]
-            [logseq.db.frontend.validate :as db-validate]
-            [malli.core :as m]
-            [malli.error :as me]
-            [nbb.core :as nbb]))
-
-(def spec
-  "Options spec"
-  {:help {:alias :h
-          :desc "Print help"}})
-
-(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!")))
-
-(defn- validate-graph [graph-dir options]
-  (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)))]
-    (validate-db @conn db-name options)))
-
-(defn -main [argv]
-  (let [{:keys [args opts]} (cli/parse-args argv {:spec spec})
-        _ (when (or (empty? args) (:help opts))
-            (println (str "Usage: $0 GRAPH-NAME [& ADDITIONAL-GRAPHS] [OPTIONS]\nOptions:\n"
-                          (cli/format-opts {:spec spec})))
-            (js/process.exit 1))]
-    (doseq [graph-dir args]
-      (validate-graph graph-dir opts))))
-
-(when (= nbb/*file* (nbb/invoked-file))
-  (-main *command-line-args*))

+ 0 - 11
docs/dev-practices.md

@@ -337,17 +337,6 @@ These tasks are specific to database graphs. For these tasks there is a one time
   $ cd deps/db && yarn install && cd ../outliner && yarn install && cd ../graph-parser && yarn install && cd ../..
 ```
 
-* `dev:validate-db` - Validates a DB graph's datascript schema
-
-  ```sh
-  # One or more graphs can be validated e.g.
-  $ bb dev:validate-db test-db schema
-  Read graph test-db with 1572 datoms, 220 entities and 13 properties
-  Valid!
-  Read graph schema with 26105 datoms, 2320 entities and 3168 properties
-  Valid!
-  ```
-
 * `dev:db-query` - Query a DB graph
 
   ```sh