소스 검색

fix: use db-based schema when possible

Tienson Qin 2 년 전
부모
커밋
0c533a9032
4개의 변경된 파일16개의 추가작업 그리고 7개의 파일을 삭제
  1. 1 1
      deps/db/src/logseq/db.cljs
  2. 12 1
      deps/db/src/logseq/db/schema.cljs
  3. 2 2
      src/main/frontend/db/restore.cljs
  4. 1 3
      src/main/frontend/publishing.cljs

+ 1 - 1
deps/db/src/logseq/db.cljs

@@ -7,7 +7,7 @@
 (defn start-conn
   "Create datascript conn with schema and default data"
   []
-  (let [db-conn (d/create-conn db-schema/schema)]
+  (let [db-conn (d/create-conn (db-schema/get-schema))]
     (d/transact! db-conn [{:schema/version db-schema/version}
                           {:block/name "card"
                            :block/original-name "card"

+ 12 - 1
deps/db/src/logseq/db/schema.cljs

@@ -1,5 +1,8 @@
 (ns logseq.db.schema
-  "Main db schema for the Logseq app")
+  "Main db schema for the Logseq app"
+  (:require [frontend.config :as config]
+            [frontend.state :as state]))
+
 
 (defonce version 2)
 (defonce ast-version 1)
@@ -109,6 +112,14 @@
    {:property/schema {}
     :property/name {:db/unique :db.unique/identity}}))
 
+(defn get-schema
+  ([]
+   (get-schema (state/get-current-repo)))
+  ([repo]
+   (if (config/db-based-graph? repo)
+     schema-for-db-based-graph
+     schema)))
+
 (def retract-attributes
   #{
     :block/refs

+ 2 - 2
src/main/frontend/db/restore.cljs

@@ -44,13 +44,13 @@
    stored: the text to restore from"
   [repo stored]
   (p/let [db-name (db-conn/datascript-db repo)
-          db-conn (d/create-conn db-schema/schema)
+          db-conn (d/create-conn (db-schema/get-schema repo))
           _ (swap! db-conn/conns assoc db-name db-conn)
           _ (when stored
               (let [stored-db (try (db-utils/string->db stored)
                                    (catch :default _e
                                      (js/console.warn "Invalid graph cache")
-                                     (d/empty-db db-schema/schema)))
+                                     (d/empty-db (db-schema/get-schema repo))))
                     attached-db (d/db-with stored-db
                                            default-db/built-in-pages) ;; TODO bug overriding uuids?
                     db (if (old-schema? attached-db)

+ 1 - 3
src/main/frontend/publishing.cljs

@@ -53,9 +53,7 @@
   (state/set-current-repo! "local")
   (when-let [data js/window.logseq_db]
     (let [data (unescape-html data)
-          ;; FIXME: how to decide which schema to use here?
-          ;; db-schema/schema or db-schema/schema-for-db-based-graph?
-          db-conn (d/create-conn db-schema/schema)
+          db-conn (d/create-conn (db-schema/get-schema))
           _ (swap! db/conns assoc "logseq-db/local" db-conn)
           db (db/string->db data)]
       (reset! db-conn db))))