datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
souenzzo 2020-09-02T13:16:21.189200Z

https://docs.datomic.com/on-prem/clojure/index.html#datomic.api/transact This doc string need a update it says "If the transaction times out, the call to transact itself will throw a RuntimeException" I got "clojure.lang.ExceptionInfo: :db.error/transaction-timeout Transaction timed out."

alexmiller 2020-09-02T13:20:42.189400Z

ExceptionInfo is a RuntimeException

joshkh 2020-09-02T14:42:38.191900Z

i remember once having to run d/administer-system as part of a Datomic Cloud upgrade, but i can't find any historical mention of it in the release notes. is that something we should be doing regularly when upgrading?

favila 2020-09-02T16:00:09.192700Z

It’s only purpose right now is to upgrade schema on a db created with a version that predates the various features that introduced new schema. so you only run it once

favila 2020-09-02T16:00:19.193100Z

these are on-prem docs, but the same applies

favila 2020-09-02T16:00:26.193300Z

I can’t find equivalent cloud docs

favila 2020-09-02T16:01:10.193500Z

so you should definitely not be running it regularly

nando 2020-09-02T20:14:44.196400Z

Beginner here. To "update" an entity, must the entity have a :db.unique/identity attribute? Or is there a way to rely on the datomic assigned entity id for this? https://docs.datomic.com/cloud/transactions/transaction-processing.html#unique-identities

favila 2020-09-02T20:23:36.196500Z

It may help to think backwards. All transactions must eventually fully expand to a set of [:db/add e a v] or [:db/retract e a v] operations. Maps are a syntax sugar for :db/add s

favila 2020-09-02T20:26:40.196700Z

the sugar is either 1) Your map has an explicit :db/id with an entity identifier (entity id, lookup-ref, or ident) 2) your map has a tempid, or 3) your map has no :db/id at all, so it gets a tempid automatically

favila 2020-09-02T20:27:08.196900Z

later, after full expansion, some “e”s will be entity ids and some will still be tempids

Yuriy Zaytsev 2020-09-02T20:28:13.197400Z

Hi there. I have a question about analytics. I want to have separate metaschemas for development and for production. What is the best way to do it? If I have for example 2 metaschemas in which order it will be applied?

favila 2020-09-02T20:28:14.197500Z

if an e is a tempid and there’s an assertion that mentions a unique-identity attribute that already exists, the tempid can be substituted for the already-existing id

favila 2020-09-02T20:28:31.197700Z

otherwise the tempid will be replaced with a newly-minted id

nando 2020-09-02T20:30:38.198Z

So I can use the entity id of an entity in :db/id to update that entity?

favila 2020-09-02T20:30:48.198200Z

so, stepping back, you can do this {:db/id 1234 :foo "bar"} or {:db/id [:unique-attr "value"] :foo "bar"} or {:db/id :ident-value :foo "bar"} if you want to be explicit about what entity you want to assert on

favila 2020-09-02T20:31:34.198400Z

this “upsertion” case should really be the less common case, and only matters if you want create-or-update behavior.

favila 2020-09-02T20:32:26.198600Z

that said, you should still use a unique attribute of some kind (not necessarily unique-identity--unique-value is ok) to identify your entities rather than raw entity ids

nando 2020-09-02T20:34:22.198800Z

Ok, so generally speaking, I should add UUID attributes to all entities in my schema, unless some other attribute will be unique. Correct?

favila 2020-09-02T20:35:10.199100Z

all entities that need to be identifiable from outside datomic should have a unique attribute

favila 2020-09-02T20:35:59.199400Z

sometimes you don’t need this. e.g. many isComponent entities have no meaning aside from their “parent” entity, and it’s often ok to not give these unique ids

favila 2020-09-02T20:37:29.199600Z

the functions that construct txs that manipuate them will have a proper identifier for the parent and will find them that way

nando 2020-09-02T20:38:17.199800Z

Ok, thanks very much for your help.

👍 2
favila 2020-09-02T20:40:35.200100Z

glad to help, sorry if that was long-winded