mirror of https://github.com/logseq/logseq
fix: don't transact initial data when importing sqlite
parent
34c632a81c
commit
ca6b2db92e
|
@ -91,16 +91,18 @@
|
|||
(defn start!
|
||||
([repo]
|
||||
(start! repo {}))
|
||||
([repo {:keys [listen-handler db-graph?]}]
|
||||
([repo {:keys [listen-handler db-graph? transact-initial-data?]
|
||||
:or {transact-initial-data? true}}]
|
||||
(let [db-name (datascript-db repo)
|
||||
db-conn (ldb/start-conn :schema (get-schema repo) :create-default-pages? false)]
|
||||
(swap! conns assoc db-name db-conn)
|
||||
(when db-graph?
|
||||
(d/transact! db-conn [(kv :db/type "db")])
|
||||
(d/transact! db-conn [(kv :schema/version db-schema/version)]))
|
||||
(when listen-handler
|
||||
(listen-handler repo))
|
||||
(ldb/create-default-pages! db-conn {:db-graph? db-graph?}))))
|
||||
(when transact-initial-data?
|
||||
(when db-graph?
|
||||
(d/transact! db-conn [(kv :db/type "db")])
|
||||
(d/transact! db-conn [(kv :schema/version db-schema/version)]))
|
||||
(ldb/create-default-pages! db-conn {:db-graph? db-graph?})))))
|
||||
|
||||
(defn destroy-all!
|
||||
[]
|
||||
|
|
|
@ -361,10 +361,12 @@
|
|||
(p/finally delete-db-f)))))
|
||||
|
||||
(defn start-repo-db-if-not-exists!
|
||||
[repo]
|
||||
[repo & {:as opts}]
|
||||
(state/set-current-repo! repo)
|
||||
(db/start-db-conn! repo {:listen-handler db-listener/listen-and-persist!
|
||||
:db-graph? (config/db-based-graph? repo)}))
|
||||
(db/start-db-conn! repo (merge
|
||||
opts
|
||||
{:listen-handler db-listener/listen-and-persist!
|
||||
:db-graph? (config/db-based-graph? repo)})))
|
||||
|
||||
(defn- setup-local-repo-if-not-exists-impl!
|
||||
[]
|
||||
|
@ -529,23 +531,24 @@
|
|||
(when (util/electron?)
|
||||
(ipc/ipc "graphReady" graph)))
|
||||
|
||||
(defn- create-db [full-graph-name {:keys [restore-db?]}]
|
||||
(defn- create-db [full-graph-name {:keys [restore-db?] :as opts}]
|
||||
(p/let [_ (persist-db/<new full-graph-name)
|
||||
_ (op-mem-layer/<init-load-from-indexeddb! full-graph-name)
|
||||
_ (start-repo-db-if-not-exists! full-graph-name)
|
||||
opts (if restore-db? (assoc opts :transact-initial-data? false) opts)
|
||||
_ (start-repo-db-if-not-exists! full-graph-name opts)
|
||||
_ (state/add-repo! {:url full-graph-name})
|
||||
_ (route-handler/redirect-to-home!)
|
||||
_ (when restore-db?
|
||||
(restore-and-setup-repo! full-graph-name))
|
||||
_ (when-not restore-db?
|
||||
(db/transact! full-graph-name [(react/kv :db/type "db")
|
||||
(react/kv :schema/version db-schema/version {:id -2})])
|
||||
(react/kv :schema/version db-schema/version {:id -2})])
|
||||
(let [initial-data (sqlite-create-graph/build-db-initial-data config/config-default-content)]
|
||||
(db/transact! full-graph-name initial-data)
|
||||
(repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)))
|
||||
(repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)
|
||||
(state/pub-event! [:page/create (date/today) {:redirect? false}])))
|
||||
;; TODO: handle global graph
|
||||
_ (state/pub-event! [:init/commands])
|
||||
_ (state/pub-event! [:page/create (date/today) {:redirect? false}])]
|
||||
_ (state/pub-event! [:init/commands])]
|
||||
(js/setTimeout ui-handler/re-render-root! 100)
|
||||
(prn "New db created: " full-graph-name)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue