Is it legal to reuse aliases for other attributes?

E.g there is an alias :Comment/text on :Comment/text.v1 but I want to use :Comment/text for :Comment/text.v2 now, my steps to test this case are the next:

1: Set alias on :Comment/text.v1

(d/transact
      connComment
[[:db/add :Comment/text.v1 :db/ident :Comment/text]
 ])

2: So, :Comment/text can be used for transacting and querying, everything is expected

Now, I want to use :Comment/text for :Comment/text.v2:

3: I believe the alias should be retracted from idents of previous attribute

 (d/transact
      connComment
[[:db/retract :Comment/text.v1 :db/ident :Comment/text]
 ])

So, the transaction is executed successfully,

4: But after executing the above transaction :Comment/text still can be used, okay, no problem, unsetting from old attribute and setting for new one can be executed within the same transaction

 (d/transact
      connComment 
[[:db/retract :Comment/text.v1 :db/ident :Comment/text] [:db/add :Comment/text.v2 :db/ident :Comment/text]
 ] )

Now :Comment/text points to :Comment/text.v2. What Iā€™m wondering whether it is legal way to reuse aliases by other attributes

P.S. After retracting alias from attribute datomic UI does not work(attributes tree panel)

Stack trace in UI console:

java.lang.NullPointerException
	at clojure.core$namespace.invokeStatic(core.clj:1603)
	at clojure.core$namespace.invoke(core.clj:1597)
	at clojure.core$comp$fn__5807.invoke(core.clj:2569)
	at clojure.core$group_by$fn__8507.invoke(core.clj:7156)
	at clojure.core.protocols$naive_seq_reduce.invokeStatic(protocols.clj:62)
1 Like

You can indeed reuse an ident alias. The docs covering this approach can be found here: https://docs.datomic.com/on-prem/schema.html#renaming-an-identity

However, I would point out that changing aliased identity is not generally recommended and I would suggest avoiding it if possible.

1 Like