Browse Source

fix: malli schema missing two ref attributes

Validator errored when I collapsed a property. Added a sync
check so that future changes to datascript schema alert developer
to make a change in the malli schema.
Also removed a ds attribute for DB schema
Gabriel Horner 2 years ago
parent
commit
075efcb222

+ 24 - 1
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -1,6 +1,7 @@
 (ns logseq.db.frontend.malli-schema
   "Malli schemas and fns for logseq.db.frontend.*"
   (:require [clojure.walk :as walk]
+            [clojure.string :as string]
             [datascript.core :as d]
             [logseq.db.frontend.schema :as db-schema]
             [logseq.db.frontend.property :as db-property]
@@ -89,6 +90,7 @@
    [:block/original-name :string]
    [:block/type {:optional true} [:enum #{"property"} #{"class"} #{"object"} #{"whiteboard"} #{"hidden"}]]
    [:block/journal? :boolean]
+   [:block/alias {:optional true} [:set :int]]
     ;; TODO: Should this be here or in common?
    [:block/path-refs {:optional true} [:set :int]]])
 
@@ -212,6 +214,7 @@
    [:block/path-refs {:optional true} [:set :int]]
    [:block/macros {:optional true} [:set :int]]
    [:block/link {:optional true} :int]
+   [:block/collapsed-properties {:optional true} [:set :int]]
     ;; other
    [:block/marker {:optional true} :string]
    [:block/priority {:optional true} :string]
@@ -289,4 +292,24 @@
     schema-version
     db-ident
     macro
-    unknown-block]])
+    unknown-block]])
+
+;; Keep malli schema in sync with db schema changes
+(let [malli-many-ref-attrs (->> (concat page-attrs block-attrs page-or-block-attrs)
+                                (filter #(= (last %) [:set :int]))
+                                (map first)
+                                set)]
+  (when-let [undeclared-ref-attrs (seq (remove malli-many-ref-attrs db-schema/card-many-ref-type-attributes))]
+    (throw (ex-info (str "The malli DB schema is missing the following cardinality-many ref attributes from datascript's schema: "
+                         (string/join ", " undeclared-ref-attrs))
+                    {}))))
+
+(let [malli-one-ref-attrs (->> (concat page-attrs block-attrs page-or-block-attrs (rest normal-page))
+                               (filter #(= (last %) :int))
+                               (map first)
+                               set)
+      attrs-to-ignore #{:block/file}]
+  (when-let [undeclared-ref-attrs (seq (remove (some-fn malli-one-ref-attrs attrs-to-ignore) db-schema/card-one-ref-type-attributes))]
+    (throw (ex-info (str "The malli DB schema is missing the following cardinality-one ref attributes from datascript's schema: "
+                         (string/join ", " undeclared-ref-attrs))
+                    {}))))

+ 1 - 1
deps/db/src/logseq/db/frontend/schema.cljs

@@ -121,7 +121,7 @@
 
 (def schema-for-db-based-graph
   (merge
-   (dissoc schema :block/properties-text-values :block/pre-block? :recent/pages :file/handle)
+   (dissoc schema :block/properties-text-values :block/pre-block? :recent/pages :file/handle :block/file)
    {:file/last-modified-at {}}))
 
 ;; TODO: some attributes shouldn't be retracted for the db version