fix: built-in properties with :name have incorrect names

Properties like logseq.table.version weren't available to add.
Also added conflict detection on properties graph which is how I
indirectly found this bug
This commit is contained in:
Gabriel Horner
2024-04-02 15:57:33 -04:00
parent 8a38390ff2
commit 661cdc8636
3 changed files with 14 additions and 15 deletions

View File

@@ -152,11 +152,8 @@
as a set. The following property types are supported: :default, :url,
:checkbox, :number, :page and :date. :checkbox and :number values are written
as booleans and integers. :page and :block are references that are written as
vectors e.g. `[:page \"PAGE NAME\"]` and `[:block \"block content\"]`
This fn also takes an optional map arg which supports these keys:
* :property-uuids - A map of property keyword names to uuids to provide ids for built-in properties"
[{:keys [pages-and-blocks properties]} & {:as options}]
vectors e.g. `[:page \"PAGE NAME\"]` and `[:block \"block content\"]`"
[{:keys [pages-and-blocks properties]}]
(let [;; add uuids before tx for refs in :properties
pages-and-blocks' (mapv (fn [{:keys [page blocks]}]
(cond-> {:page (merge {:block/uuid (random-uuid)} page)}
@@ -176,9 +173,7 @@
db-ident
prop-name
(assoc (get properties prop-name) :db/ident db-ident)
{:icon-id
(get-in options [:property-uuids :icon])
:translate-closed-page-value-fn
{:translate-closed-page-value-fn
#(hash-map :block/uuid (translate-property-value (:value %) uuid-maps))
:property-attributes
{:db/id (or (property-db-ids (name prop-name))

View File

@@ -8,6 +8,7 @@
[logseq.db.frontend.property.type :as db-property-type]
[clojure.string :as string]
[clojure.edn :as edn]
[clojure.set :as set]
[datascript.core :as d]
["path" :as node-path]
["os" :as os]
@@ -185,9 +186,12 @@
((juxt node-path/dirname node-path/basename) graph-dir)
[(node-path/join (os/homedir) "logseq" "graphs") graph-dir])
conn (create-graph/init-conn dir db-name {:additional-config (:config options)})
blocks-tx (create-graph/create-blocks-tx
(create-init-data)
{:property-uuids {:icon (:block/uuid (d/entity @conn :logseq.property/icon))}})]
blocks-tx (create-graph/create-blocks-tx (create-init-data))
existing-names (set (map :v (d/datoms @conn :avet :block/original-name)))
conflicting-names (set/intersection existing-names (set (keep :block/original-name blocks-tx)))]
(when (seq conflicting-names)
(println "Error: Following names conflict -" (string/join "," conflicting-names))
(js/process.exit 1))
(println "Generating" (count (filter :block/name blocks-tx)) "pages and"
(count (filter :block/content blocks-tx)) "blocks ...")
(d/transact! conn blocks-tx)