Hi, I noticed that if I add a :db.unique/identity after datoms having the attribute already created, the constraint is never enforced. Below is my reproduction.
(def in-mem-connection2
(do (d/create-database "datomic:mem://datamodel-schema4")
(d/connect "datomic:mem://datamodel-schema4")))
(d/transact in-mem-connection2
[#:db{:ident :foo/unique-entity
:valueType :db.type/string,
:cardinality :db.cardinality/one}
#:db{:ident :foo/bar
:valueType :db.type/string,
:cardinality :db.cardinality/one}])
(d/transact in-mem-connection2
[{:foo/unique-entity "foo"
:foo/bar "bee"}
{:foo/unique-entity "foo"
:foo/bar "bea"}])
;; Succeeds even though violating records exist.
(d/transact in-mem-connection2
[#:db{:unique :db.unique/identity
:ident :foo/unique-entity}])
;; Succeeds
(d/transact in-mem-connection2
[{:foo/unique-entity "foo"
:foo/bar "baa"}])
Tested with com.datomic/datomic-pro 0.9.6045 and in mem db.
If the :db/unique/identity is added before any records are transacted it does throw exceptions as expected.
Also queried the schema entity and indeed there was a :db.unique/unique-identity.