Fix: circular dependencies again b/n deps <-> frontend

Breaks setup of deps/ and most tests
pull/10016/head
Gabriel Horner 2023-06-27 16:39:10 -04:00
parent c11e94ed59
commit 75ff4db4aa
6 changed files with 19 additions and 27 deletions

View File

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

View File

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

View File

@ -71,9 +71,3 @@
(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))

View File

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

View File

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

View File

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