Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retract attributes in Datomic?

i've created a set of attributes in the Datomic schema. Their :db/idents are grouped into three namespaces: :name, :tree, :node. Now i want to delete all of these and start fresh. I've found all of the required attributes:

(def results 
  (q '[:find ?e 
       :where [?e :db/ident ?v]
              [(namespace ?v) ?res]
              [(contains? #{"task", "node", "tree"} ?res)]
     ] 
     (db conn)))

Then created a set of retractEntity statements:

(def retract-statements 
  (into [] (map #(vector :db.fn/retractEntity (first %1)) results)))

And now i'm trying to invoke the transaction:

@(d/transact conn [retract-statements])

It gives me: :db.error/invalid-attribute Schema change must be followed by :db.install/attribute or :db.alter/attribute

Apparently i'm doing something wrong. Can someone please help?

Thanks!

like image 327
siphiuel Avatar asked Feb 13 '23 02:02

siphiuel


1 Answers

There is no way to directly retract attributes in Datomic. Once you install an attribute, it's around forever unless you delete the entire database. This makes sense, given that Datomic (except in the special case of excision) never truly deletes any data - if you could actually remove attributes, then data originally transacted against those attributes would not be retrievable.

Note that you can rename attributes, but that it still keeps its old ident as a synonym as well unless you repurpose it for something else.

like image 146
levand Avatar answered Feb 22 '23 10:02

levand