diff --git a/deps/db/src/logseq/db.cljs b/deps/db/src/logseq/db.cljs index f842bb0ebf..ab91139bb5 100644 --- a/deps/db/src/logseq/db.cljs +++ b/deps/db/src/logseq/db.cljs @@ -2,17 +2,26 @@ "Main namespace for public db fns" (:require [logseq.db.default :as default-db] [logseq.db.schema :as db-schema] - [datascript.core :as d])) + [datascript.core :as d] + [cljs-time.core :as t] + [cljs-time.coerce :as tc])) (defn create-default-pages! "Creates default pages if one of the default pages does not exist. This fn is idempotent" [db-conn] (when-not (d/entity @db-conn [:block/name "card"]) - (d/transact! db-conn - (concat - [{:schema/version db-schema/version}] - default-db/built-in-pages)))) + (let [time (tc/to-long (t/now)) + built-in-pages-with-timestamp (map + (fn [m] + (-> m + (assoc :block/created-at time) + (assoc :block/updated-at time))) + default-db/built-in-pages)] + (d/transact! db-conn + (concat + [{:schema/version db-schema/version}] + built-in-pages-with-timestamp))))) (defn start-conn "Create datascript conn with schema and default data" diff --git a/src/main/frontend/db/restore.cljs b/src/main/frontend/db/restore.cljs index a10d909042..26d3f87334 100644 --- a/src/main/frontend/db/restore.cljs +++ b/src/main/frontend/db/restore.cljs @@ -48,11 +48,9 @@ (catch :default _e (js/console.warn "Invalid graph cache") (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) - (db-migrate/migrate attached-db) - attached-db)] + db (if (old-schema? stored-db) + (db-migrate/migrate stored-db) + stored-db)] (db-conn/reset-conn! db-conn db)))] (d/transact! db-conn [{:schema/version db-schema/version}]))) @@ -74,9 +72,9 @@ (str "DB init! " (count all-datoms) " datoms") (d/init-db all-datoms schema))) new-db (sqlite-restore/restore-other-data conn data uuid->db-id-map {:init-db-fn profiled-init-db})] - + (reset! conn new-db) - + (let [end (util/time-ms)] (println "[debug] load others from SQLite: " (int (- end start)) " ms."))