diff --git a/deps/db/src/logseq/db.cljs b/deps/db/src/logseq/db.cljs index bd183d37f3..ff030d4593 100644 --- a/deps/db/src/logseq/db.cljs +++ b/deps/db/src/logseq/db.cljs @@ -19,9 +19,10 @@ (defn start-conn "Create datascript conn with schema and default data" - [& {:keys [create-default-pages?] - :or {create-default-pages? true}}] - (let [db-conn (d/create-conn (db-schema/get-schema))] + [& {:keys [create-default-pages? schema] + :or {create-default-pages? true + schema db-schema/schema}}] + (let [db-conn (d/create-conn schema)] (when create-default-pages? (create-default-pages! db-conn)) db-conn)) diff --git a/deps/db/src/logseq/db/schema.cljs b/deps/db/src/logseq/db/schema.cljs index 40392991fc..933f424fce 100644 --- a/deps/db/src/logseq/db/schema.cljs +++ b/deps/db/src/logseq/db/schema.cljs @@ -1,8 +1,5 @@ (ns logseq.db.schema - "Main db schema for the Logseq app" - (:require [frontend.config :as config] - [frontend.state :as state])) - + "Main db schemas for the Logseq app") (defonce version 2) (defonce ast-version 1) @@ -112,14 +109,6 @@ schema {})) -(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 diff --git a/src/main/frontend/db.cljs b/src/main/frontend/db.cljs index a186c0e712..af2951783b 100644 --- a/src/main/frontend/db.cljs +++ b/src/main/frontend/db.cljs @@ -70,10 +70,4 @@ (defn new-block-id [] - (d/squuid)) - -(defn get-schema - [repo] - (if (config/db-based-graph? repo) - db-schema/schema-for-db-based-graph - db-schema/schema)) + (d/squuid)) \ No newline at end of file diff --git a/src/main/frontend/db/conn.cljs b/src/main/frontend/db/conn.cljs index 148e701722..08a7c5bfdc 100644 --- a/src/main/frontend/db/conn.cljs +++ b/src/main/frontend/db/conn.cljs @@ -8,6 +8,7 @@ [frontend.util.text :as text-util] [logseq.graph-parser.text :as text] [logseq.db :as ldb] + [logseq.db.schema :as db-schema] [logseq.graph-parser.util :as gp-util])) (defonce conns (atom {})) @@ -52,6 +53,13 @@ (str (if (util/electron?) "" config/idb-db-prefix) path)))) +(defn get-schema + "Returns schema for given repo" + [repo] + (if (config/db-based-graph? repo) + db-schema/schema-for-db-based-graph + db-schema/schema)) + (defn get-db ([] (get-db (state/get-current-repo) true)) @@ -78,7 +86,7 @@ (start! repo {})) ([repo {:keys [listen-handler]}] (let [db-name (datascript-db repo) - db-conn (ldb/start-conn :create-default-pages? false)] + db-conn (ldb/start-conn :schema (get-schema repo) :create-default-pages? false)] (swap! conns assoc db-name db-conn) (when listen-handler (listen-handler repo)) diff --git a/src/main/frontend/db/restore.cljs b/src/main/frontend/db/restore.cljs index dbe46326c3..57b4767f7f 100644 --- a/src/main/frontend/db/restore.cljs +++ b/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/get-schema repo)) + db-conn (d/create-conn (db-conn/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/get-schema repo)))) + (d/empty-db (db-conn/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) diff --git a/src/main/frontend/publishing.cljs b/src/main/frontend/publishing.cljs index 9918f663c7..05276108b4 100644 --- a/src/main/frontend/publishing.cljs +++ b/src/main/frontend/publishing.cljs @@ -4,8 +4,8 @@ (:require [frontend.state :as state] [datascript.core :as d] [frontend.db :as db] + [frontend.db.conn :as conn] [frontend.db.listener :as db-listener] - [logseq.db.schema :as db-schema] [rum.core :as rum] [frontend.handler.route :as route-handler] [frontend.page :as page] @@ -53,7 +53,7 @@ (state/set-current-repo! "local") (when-let [data js/window.logseq_db] (let [data (unescape-html data) - db-conn (d/create-conn (db-schema/get-schema)) + db-conn (d/create-conn (conn/get-schema (state/get-current-repo))) _ (swap! db/conns assoc "logseq-db/local" db-conn) db (db/string->db data)] (reset! db-conn db))))