Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 143 additions & 1 deletion test/datahike/test/migrate_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[datahike.datom :as datom]
[datahike.migrate :as m]
[datahike.db.utils :as dbu]
[datahike.test.utils :as utils]))
[datahike.test.utils :as utils])
(:import [java.util UUID]))

(def tx-data [[:db/add 1 :db/cardinality :db.cardinality/one 536870913 true]
[:db/add 1 :db/ident :name 536870913 true]
Expand Down Expand Up @@ -295,3 +296,144 @@
(d/datoms @import-conn :eavt)))))
(d/release conn)
(d/release import-conn)))

(def taxonomy-data0
[[76 :db/ident :relation/id 13194139533318 true]
[77 :db/ident :concept/id 13194139533318 true]
[77 :db/valueType :db.type/string 13194139533318 true]
[77 :db/unique :db.unique/identity 13194139533318 true]
[112 :db/valueType :db.type/string 13194139533318 true]
[113 :db/ident :relation/concept-1 13194139533318 true]
[113 :db/valueType :db.type/ref 13194139533318 true]
[114 :db/ident :relation/concept-2 13194139533318 true]
[114 :db/valueType :db.type/ref 13194139533318 true]
[124 :db/ident :webhook/url 13194139533318 true]
[118747255884125
:relation/concept-1
92358976749187
13194139533332
true]
[129 :db/valueType :db.type/string 13194139540571 true]
[149533581525767 :concept/id "qLqq_iDq_Ua4" 13194139543922 true]
[149533581525768
:relation/id
"qLqq_iDq_Ua4:broad-match:haMy_QRx_7vg"
13194139543923
true]
[149533581525768
:relation/concept-1
149533581525767
13194139543923
true]
[149533581525788
:relation/id
"2x2V_UeL_6ke:related:SpRR_JX9_6o6"
13194139543944
true]
[149533581525788
:relation/concept-1
136339441992474
13194139543944
true]
[149533581525788
:relation/concept-2
92358976749187
13194139543944
true]
[149533581525788
:relation/concept-1
92358976749187
13194139543945
true]
[149533581525768
:relation/concept-1
149533581525767
13194139624849
false]
[193514046695117
:relation/id
"qLqq_iDq_Ua4:broad-match:haMy_QRx_7vg"
13194139624850
true]
[193514046695117
:relation/concept-1
149533581525767
13194139624850
true]])

(deftest test-load-taxonomy-data0
(let [cfg {:attribute-refs? true
:index :datahike.index/persistent-set
:keep-history true
:name (str "jobtech-taxonomy-db" (rand-int 9999999))
:schema-flexibility :write
:store {:backend :memory
:id (UUID/randomUUID)}}]
(try
(d/create-database cfg)
(let [conn (d/connect cfg)
_ @(d/load-entities conn taxonomy-data0)
db (d/db conn)
raw-eavt-datoms (d/datoms db {:index :eavt :limit -1})

ident (some (fn [[e a v]]
(when (and (= e a) (= :db/ident v)) e))
raw-eavt-datoms)
eid->attrib (into {}
(keep (fn [[e a v]]
(when (= a ident)
[e v])))
raw-eavt-datoms)
interesting-attrib? #(not= "db" (namespace %))
map-attribs (fn [raw-datoms]
(into #{}
(keep
(fn [[e a v tx added]]
(let [attrib (eid->attrib a)]
(when (interesting-attrib? attrib)
[e attrib v tx added]))))
raw-datoms))
raw-avet-datoms (d/datoms db {:index :avet :limit -1})
eavt-datoms (map-attribs raw-eavt-datoms)
avet-datoms (map-attribs raw-avet-datoms)

extract-test-sample
(fn [datoms]
(let [[concept-eid] (keep
(fn [[e a v]]
(when (= [:concept/id "qLqq_iDq_Ua4"]
[a v])
e))
datoms)]
(into #{}
(filter (fn [[_ a v _ added]]
(= [:relation/concept-1 concept-eid true]
[a v added])))
datoms)))

;; Just pick out the datom(s) that we are
;; interested in.
eavt-sample (extract-test-sample eavt-datoms)
avet-sample (extract-test-sample avet-datoms)]

;; The equality (= eavt-datoms avet-datoms) does not
;; seem to hold. I am not sure whether this is generally
;; expected, or not.

(is (= 1 (count eavt-sample)))
(is (= eavt-sample avet-sample))

(is (= (into #{}
(map (fn [[e _ v]] [e v]))
eavt-sample)
(into #{}
(d/q '[:find ?r ?c
:in $ ?concept-id
:where
[?c :concept/id ?concept-id]
[?r :relation/concept-1 ?c]]
db
"qLqq_iDq_Ua4")))))
(finally
(d/delete-database cfg)))))