fix: add validation for property types and :schema attributes

Part of LOG-2953. We shouldn't persist unusuable property type
configurations as shown by this bug. By enumerating what schema
attributes are allowed for each type, we can prevent future bugs
like this. When changing between property types, this also cleans up
:classes, :position and :values that were accidentally hanging around
for certain types. Also modify test since we don't allow users
to use a :default property with :cardinality
This commit is contained in:
Gabriel Horner
2023-11-30 14:47:44 -05:00
parent d218db4e6f
commit f5e339293f
5 changed files with 103 additions and 53 deletions

View File

@@ -4,6 +4,7 @@
NOTE: This script is also used in CI to confirm graph creation works"
(:require [logseq.tasks.db-graph.create-graph :as create-graph]
[logseq.db.sqlite.util :as sqlite-util]
[logseq.db.frontend.property.type :as db-property-type]
[clojure.string :as string]
[datascript.core :as d]
["path" :as node-path]
@@ -70,7 +71,7 @@
:properties
(->> [:default :url :checkbox :number :page :date]
(mapcat #(cond-> [[% {:block/schema {:type %}}]]
(not (#{:checkbox :default} %))
(db-property-type/property-type-allows-schema-attribute? % :cardinality)
(conj [(keyword (str (name %) "-many")) {:block/schema {:type % :cardinality :many}}])))
(into {}))}))