Fork me on GitHub
#datomic
<
2019-11-26
>
cjmurphy06:11:36

When I create entities I always give them an attribute called :base/type , which is just a keyword, for instance :bank-account . I'd like to find all the entities (preferably that I've created) that don't have this attribute. I've asked this on Stack Overflow: https://stackoverflow.com/questions/58866423/find-all-entities-that-are-missing-a-particular-attribute, but no answers...

benoit12:11:08

@U0D5RN0S1 you would have to somehow reduce the number of entities to check otherwise you're doing a full db scan. So I would write first the clause to identify all the entities you've created and then from those, find all the entities without this attribute.

benoit12:11:09

Unfortunately it is not explained in the missing? section of the docs and all examples just happend to have clauses before the missing? predicate that makes the query work (`[?artist :artist/name ?name]`)

cjmurphy20:11:27

Thanks @U963A21SL that brings things together for me. I can work with knowing the name of an attribute in the entity that may not have a :base/type.

cjmurphy20:11:36

[:find [?entities ...]
       :in $ :where
       [?entities ::rule/splits ?s]
       [(missing? $ ?entities :base/type)]]

leongrapenthin12:11:52

Where do I find the upgrade instructions from solo to production?

marshall12:11:40

Just choose a production compute stack instead of a solo compute stack. You should be running a split stack first

joshkh13:11:30

An attribute which is unique by identity allows us to use its value instead of a :db/id to identify an entity within a transaction. If no entity exists with that value then an entity is created, otherwise facts are stored about the existing entity. Do composite tuples work the same way? They are also :db.unique/identity, however they seem to operate more like :db.unique/value in that they throw an exception when the tuple value already exists.

joshkh13:11:03

Or in other words, can I take advantage of a tuple to update an existing entity? For example, change this player's colour based on the combination of their first and last name:

{:tx-data [{
            ; composite tuple attributes:
            :player/first-name "Jean-Luc"
            :player/last-name  "Picard"
            
            ; some fact to store about the existing entity
            :player/colour     "blue"
            }]}
Edit: the code example throws a Unique conflict exception when transacted a second time

marshall14:11:42

You can indeed use a composite tuple for identity and upsert. You have to include the tuple itself in the transaction So in your example, if the unique attribute is called :player/first+last, you need to include a value for :player/first+last in your next transaction to get upsert

joshkh14:11:12

Thanks @marshall, you just made my day.

👍 4
joshkh14:11:03

I came across that post a few months ago when I first encountered the same problem, but to be honest I didn't understand the resolution in the comments.

joshkh15:11:25

i'm attempting to transact a tuple ident and am getting the following exception:

(d/transact (client/get-conn)
            {:tx-data [
                       {:db/ident       :user/first+last
                        :db/valueType   :db.type/tuple
                        :db/tupleAttrs  [:user/first :user/last]
                        :db/cardinality :db.cardinality/one
                        :db/unique      :db.unique/identity}
                       ]})

Unable to resolve entity: :db/tupleAttrs
any ideas? i have no problem transacting it to another database an hour ago.

favila15:11:09

This db was created with an older (pre-tuple) version of datomic?

favila15:11:42

You need to transact these new schema attributes using administer-system

ghadi15:11:44

If so, you have to run d/administer-system as in the documentation

joshkh15:11:53

this applies to cloud as well?

joshkh15:11:37

silly question, of course it does as i'm missing the attributes 😉

joshkh15:11:42

great, that did the trick. thanks favila and ghadi!

leongrapenthin16:11:42

is it technically possible/viable to downgrade the production primary compute group instance type to something cheaper as long as you don't have users?

marshall16:11:03

the supported instance types are fixed

marshall16:11:09

you can, however, reduce your ASG size to 1

marshall16:11:15

if you don’t need HA

leongrapenthin16:11:47

reducing asg size

leongrapenthin16:11:06

still, its a factor ten price difference at least

marshall16:11:44

from solo - prod?

marshall16:11:08

fair enough; we are definitely taking feedabck and considering options

marshall16:11:27

also, you can ‘turn off’ the system over nights/weekends if it’s not a user-facing prod system

marshall16:11:32

same technique - ASG to 0

leongrapenthin16:11:34

as long as my customer is not live, I will have difficulty explaining this price to him

marshall16:11:47

we’re also looking into tooling that will make that somewhat easier to do/manage

leongrapenthin16:11:06

simultaneously, I need the architecture at some point, to develop against prod. only features like http-direct

leongrapenthin16:11:19

or have staging/test query group separation

leongrapenthin16:11:15

i need the platform running for 1-5 users testing on the customer site

leongrapenthin16:11:24

turn off is no option

favila17:11:05

Are there plans to expose point-in-time queries via datomic analytics?