datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
yubrshen 2020-11-02T02:02:56.263300Z

My problems are that I don't know enough Datomic to figure out how to have "a value index". I'm studying the documentation on schema change at https://docs.datomic.com/cloud/schema/schema-change.html There are two pre-conditions:In order to add a uniqueness constraint to an attribute, both of the following must be true: > The attribute must have a cardinality of `:db.cardinality/one`. > If there are values present for that attribute, they must be unique in the set of current database assertions. For the first one, my schema for :user/email already has :db.cardinality/one. For the second one, I don't know how to handle: 1. how to check if the values present for :user/email are unique or not 2. If not, how to fix them.

yubrshen 2020-11-02T02:10:54.264Z

It's strange that once I added :db/unique to the existing schema without transacting, but just evaluate the schema definition, it works for retrieving the user by email address. But later, when I actually transacted the updated schema, then I run into trouble of "Error: {:db/error :db.error/unique-without-index, :attribute :user/email}"

lambdam 2020-11-02T10:11:29.266600Z

Hello, I'm discovering Datomic entity specs. I tried to trigger an spec error and here is the message:

"Entity temp-id missing attributes clojure.lang.LazySeq@e65620e6 of spec :admin/validate"
The doc example gives:
"Entity 42 missing attributes [:user/email] of by :user/validate"}
Clearly, the serialization of the missing attribute seems to go wrong. I'm using the latest version of Datomic (`1.0.6202` ). Is it a known problem?

lambdam 2020-11-03T16:37:55.292800Z

Here is the spec:

{:db/ident :admin/validate
 :db.entity/attrs [:admin/email :admin/hashed_password]}
and here are the attribute declarations:
{:db/ident :admin/email
 :db/valueType :db.type/string
 :db/unique :db.unique/identity
 :db/cardinality :db.cardinality/one
 :db.attr/preds myproject.entities.entity/email?}
{:db/ident :admin/hashed_password
 :db/valueType :db.type/string
 :db/cardinality :db.cardinality/one}
The only "particular" thing that I see is that the email field has an attibute predicate. Thanks

jaret 2020-11-03T17:15:14.298400Z

Hey @dam I've made a ticket to look at this more closely. I'll keep you updated on what I find could you DM me an e-mail so I can contact you in the event that this slack convo gets archived while I am poking around?

lambdam 2020-11-03T17:26:07.298600Z

Thank you very much! I do it right now.

lambdam 2020-11-02T10:34:08.273500Z

Also I noted those points that seem weird: 1 - The documentation says: :db/ensure is a virtual attribute. It is not added in the database; instead it triggers checkes based on the named entity. When I then pull all the attributes of the entity, the :db/ensure field appears.

{:db/id 17592186045425,
 :db/ensure [#:db{:id 17592186045420}],
 :user/hashed-password "...",
 ...}
I then don't get what is a "virtual attribute" then. 2 - After transacting successfully an entity with its spec "activated", I could then retract a field without triggering the entity spec:
(datomic.api/transact
  conn*
  [[:db/retract 17592186045425 :user/hashed_password]])
The resulting entity viiolates the spec but nothing was triggered. Is it the desired behaviour of entity specs? Thanks

favila 2020-11-02T12:18:59.275200Z

Are you using cloud or on prem? You cite cloud docs but this sounds like an on-prem problem. (Cloud indexs all values by default)

favila 2020-11-02T12:20:01.276300Z

On on-prem, there is a :db/index true

1🙏
2020-11-02T14:14:54.278Z

does Datomic use auto-discovery when integrating with the managed memcached in AWS? Or do we need to pass in each relevant memcached node individually?

yubrshen 2020-11-02T15:09:55.278200Z

I'm using on-prem, actually just dev one. I'll take look of :db/index tree @favila Thanks for the pointer!

favila 2020-11-02T15:10:59.278700Z

> All alterations happen synchronously, except for adding an AVET index. If you want to know when the AVET index is available, call https://docs.datomic.com/on-prem/javadoc/datomic/Connection.html#syncSchema(long). In order to add :db/unique, you must first have an AVET index including that attribute.

favila 2020-11-02T15:11:02.278900Z

(quote from the docs)

yubrshen 2020-11-02T15:25:04.279100Z

@favila Yes, the following worked:

(def tx-add-index @(d/transact conn [{:db/id :user/email
                                    :db/index true}]))
(def tx-fix @(d/transact conn [{:db/id :user/email
                                :db/unique :db.unique/identity}]))
where conn is a connection to the on-prem (dev) database. Thanks again for your coaching!

marshall 2020-11-02T17:27:54.279300Z

can you share your :admin/validate spec ?

2020-11-02T23:47:46.279500Z

do you mean apply-template in clojure.template?