fix: db/ident and schema/version shouldn't create unknown blocks

Also log unknown blocks and make their entity more explicit with the
goal of eventually resolving all unknown blocks. Also added
a query bb task. Part of LOG-2818
pull/10438/head
Gabriel Horner 2023-10-11 15:18:44 -04:00
parent fe7a46eac9
commit c8ccc79e82
5 changed files with 30 additions and 7 deletions

4
bb.edn
View File

@ -48,6 +48,10 @@
:task (apply shell {:dir "deps/db" :extra-env {"ORIGINAL_PWD" (fs/cwd)}}
"yarn -s nbb-logseq script/validate_client_db.cljs"
*command-line-args*)}
dev:db-query
{:doc "Query a DB graph's datascript db"
:task (apply shell {:dir "deps/db"} "yarn -s nbb-logseq script/query.cljs" *command-line-args*)}
dev:npx-cap-run-ios
logseq.tasks.dev.mobile/npx-cap-run-ios

View File

@ -209,13 +209,18 @@
normal-block
object-block])
;; TODO: Figure out where this is coming from
(def unknown-empty-block
;; TODO: invalid macros should not generate unknown
;; TODO: Creating an enum property should not generate unknown
(def unknown-block
"A block that has an unknown type. This type of block should be removed when
the above TODOs have been addressed and the frontend ensures no unknown blocks
are being created"
[:map {:closed true}
[:block/uuid :uuid]])
[:block/uuid :uuid]
[:block/unknown? :boolean]])
(def file-block
[:map {:closed true}
[:map {:closed false}
[:block/uuid :uuid]
[:block/tx-id {:optional true} :int]
[:file/content :string]
@ -223,6 +228,15 @@
;; TODO: Remove when bug is fixed
[:file/last-modified-at {:optional true} :any]])
(def schema-version
[:map {:closed false}
[:schema/version :int]])
(def db-ident
[:map {:closed false}
[:db/ident :keyword]
[:db/type {:optional true} :string]])
(def DB
"Malli schema for entities from schema/schema-for-db-based-graph. In order to
thoroughly validate properties, the entities and this schema should be
@ -233,4 +247,6 @@
page
block
file-block
unknown-empty-block]])
schema-version
db-ident
unknown-block]])

View File

@ -92,7 +92,8 @@
(let [eid (assign-id-to-uuid-fn (:uuid b))]
(if (and (uuid-string? (:uuid b))
(not (contains? #{3 6} (:type b)))) ; deleted blocks still refed
[[eid :block/uuid (:uuid b)]]
[[eid :block/uuid (:uuid b)]
[eid :block/unknown? true]]
(datoms-str->eav-vec (:datoms b) eid))))
init-data))
uuid->db-id-map (persistent! uuid->db-id-tmap)

View File

@ -23,7 +23,7 @@
[block]
(cond
(:block/page block) 1
(:file/content block) 3
(some #{:file/content :schema/version :db/type} (keys block)) 3
(contains? (:block/type block) "property") 6
(:block/name block) 2
:else 5))

View File

@ -381,6 +381,8 @@
(sqlite-db/delete-blocks! repo deleted-block-uuids))
(when (seq blocks)
(let [blocks' (mapv sqlite-util/ds->sqlite-block blocks)]
(when-let [unknown-blocks (seq (filter #(= 5 (:type %)) blocks'))]
(logger/error "The following blocks saved as unknown:" unknown-blocks))
(sqlite-db/upsert-blocks! repo (bean/->js blocks'))))))
;; Needs to be called first for an existing graph