datahike
datahike copied to clipboard
[Bug]: schema updates and removals are not consistent
What version of Datahike are you using?
0.5.1501
What version of Java are you using?
openjdk version "11.0.15" 2022-04-19
What operating system are you using?
Ubuntu 20.04.4 LTS
What database EDN configuration are you using?
{:store {:backend :mem
:id "schema_test"}
:keep-history? true
:schema-flexibility :write
:attribute-refs? true}
Describe the bug
There are inconsistencies when updating or removing the schema.
What is the expected behaviour?
Datahike should have a clear strategy and documentation on schema updates.
How can the behaviour be reproduced?
(require '[datahike.api :as d])
(def schema [{:db/cardinality :db.cardinality/one
:db/ident :name
:db/index true
:db/unique :db.unique/identity
:db/valueType :db.type/string}
{:db/ident :parents
:db/cardinality :db.cardinality/many
:db/valueType :db.type/ref}
{:db/ident :age
:db/cardinality :db.cardinality/one
:db/valueType :db.type/long}])
(def cfg {:store {:backend :mem
:id "schema_upgrade"}
:keep-history? true
:schema-flexibility :write
:attribute-refs? true})
(do
(d/delete-database cfg)
(d/create-database cfg))
(def conn (d/connect cfg))
(d/transact conn {:tx-data schema})
(d/schema @conn)
(d/datoms @conn :eavt)
(d/transact conn [{:name "Alice"
:age 25}
{:name "Bob"
:age 35}])
(d/transact conn [{:name "Charlie"
:age 5
:parents [[:name "Alice"] [:name "Bob"]]}])
(d/q '[:find ?e ?n
:where
[?e :name ?n]] @conn)
;;=> #{[44 "Charlie"] [43 "Bob"] [42 "Alice"]}
(d/transact conn {:tx-data [[:db/retractEntity [:db/ident :name]]]})
;; => this shouldn't be possible when there is still data with that attribute!
(d/q '[:find ?e ?n
:where
[?e :name ?n]] @conn)
;;=> #{[17 :db.type/boolean]
;; [8 11]
;; [8 :db.install/attribute]
;; [40 :parents]
;; [20 :db.type/float]
;; [1 33]
;; [9 :db/txInstant]
;; [7 11]
;; [44 43]
;; [2 "An attribute's value type"]
;; [40 25]
;; [3 19]
;; [5 "An attribute's index selection"]
;; [1 23]
;; [4 26]
;; [19 :db.type/cardinality]
;; [30 :db.type/valueType]
;; [6 28]
;; [4 :db/doc]
;; [3 :db/cardinality]
;; [40 10]
;; [42 25]
;; [6 "An attribute's unique selection"]
;; [33 :db.unique/value]
;; [36 :db/tupleTypes]
;; [41 24]
;; [536870913 #inst "2022-05-06T13:06:54.787-00:00"]
;; [29 :db.type/uuid]
;; [14 :db.part/user]
;; [7 "An attribute's history selection"]
;; [9 "A transaction's time-point"]
;; [2 :db/valueType]
;; [32 :db.unique/identity]
;; [2 30]
;; [9 true]
;; [9 22]
;; [536870914 #inst "2022-05-06T13:06:57.597-00:00"]
;; [8 "Only for interoperability with Datomic"]
;; [24 :db.type/long]
;; [34 :db/isComponent]
;; [21 :db.type/number]
;; [13 :db.part/tx]
;; [38 :db.type/tuple]
;; [4 11]
;; [536870916 #inst "2022-05-06T13:07:01.761-00:00"]
;; [1 11]
;; [44 "Charlie"]
;; [1 :db/ident]
;; [27 :db.type/symbol]
;; [16 :db.type/bigint]
;; ...}
A solution should also consider imports and exports
Issue #13 also deals with schema changes