Fork me on GitHub
#datomic
<
2017-11-28
>
luchini19:11:53

@lmergen the core idea is to give the option to users for being as specific as they want (i.e. writing migrations one at a time - complex or not) or allowing users to manage one schema and then letting Migrana deal with the migrations

lmergen19:11:09

i'm interested

luchini19:11:06

cool… I’ll put a few lines together during the next weeks

timgilbert20:11:41

Say, is there a version of :db.fn/retractEntity that doesn't recur into :db/isComponent true attributes?

favila20:11:52

No, but not deleting them doesn't make much sense if they are components. The semantics of being a "component" mean you don't outlive your parent.

favila20:11:03

Maybe these are not really component entities?

timgilbert20:11:49

Yeah, they aren't really, but they are marked as such in the database and have caused some pretty spectacular cascading deletes

favila20:11:28

The assumption for components is that (d/datoms db :vaet component-entity-id) will always show exactly 0 or 1 datom, and the attribute for that datom is :db/isComponent true

favila20:11:44

You should just remove :db/isComponent from that attribute I think?

favila20:11:20

That's a schema alteration you can do at any time.

timgilbert21:11:50

Tangentially-related to the last question: let's say I have called retractEntity on entity 123 and I want to undo the transaction. Is it safe to add the data back as [:db.add 123 :attr value] seqs, or do I need to generate a new tempid and add the data in to the newly-created entity instead?

favila22:11:28

It's safe. There's some internal counter in datomic that is the max "t" component of all entity ids. If you attempt to assert an id with a "t" component larger than the counter, your transaction will fail.

favila22:11:53

But since the entity used to have assertions on it, the counter is higher than that, so it will succeed.

souenzzo23:11:28

Wired/Cool idea about @timgilbert problem

(d/function
  '{:lang :clojure :requires [[datomic.api :as d]] :params [db eid]
    :code (as-> '[:find ?add ?attr ?comp ?v
                  :in $ ?e
                  :where
                  [(ground :db/add) ?add]
                  [(ground :db/isComponent) ?comp]
                  [(ground false) ?v]
                  [?e ?i]
                  [?i :db/valueType :db.type/ref]
                  [?i :db/ident ?attr]] ↓
                (d/q ↓ db eid)
                (d/with db ↓)
                (:db-after ↓)
                (d/invoke db :db.fn/retractEntity ↓ eid))})