Consider simple input like this:
[:db/add "foo" :thing/unique "x"]
[:db/add "foo" :thing/v 92]
[:db/add "bar" :thing/unique "x"]
[:db/add "bar" :thing/s true]
"foo" and "bar" are intended to be temporary IDs for the same entity. However, if that entity does not already exist in the store — that is, if a search with :thing/unique "x" returns no results — a new entid will be allocated for each, and insertion will fail.
.t [{:db/ident :thing/unique :db/valueType :db.type/string :db/cardinality :db.cardinality/one :db/unique :db.unique/identity :db/index true}]
.t [{:db/ident :thing/v :db/valueType :db.type/long :db/cardinality :db.cardinality/many}]
.t [{:db/ident :thing/s :db/valueType :db.type/boolean :db/cardinality :db.cardinality/one}]
.t [[:db/add "foo" :thing/unique "x"]
[:db/add "foo" :thing/v 92]
[:db/add "bar" :thing/unique "x"]
[:db/add "bar" :thing/s true]]
Error(MentatError(DbError(Msg("Could not update datoms: failed to add datoms not already present"))), State { next_error: Some(SqliteFailure(Error { code: ConstraintViolation, extended_code: 2067 }, Some("UNIQUE constraint failed: datoms.a, datoms.value_type_tag, datoms.v"))), backtrace: None }).
Fixing this means deducing equivalence between a graph of related tempids, so that only a single entid is allocated for equivalent entity placeholders. This is what the transactor does when it handles upserts, so it might be best to fix it there, perhaps by inserting collections of datoms grouped by tempid-entity in order that other tempid searches can succeed.
Consider simple input like this:
"foo" and "bar" are intended to be temporary IDs for the same entity. However, if that entity does not already exist in the store — that is, if a search with
:thing/unique "x"returns no results — a new entid will be allocated for each, and insertion will fail.Fixing this means deducing equivalence between a graph of related tempids, so that only a single entid is allocated for equivalent entity placeholders. This is what the transactor does when it handles upserts, so it might be best to fix it there, perhaps by inserting collections of datoms grouped by tempid-entity in order that other tempid searches can succeed.