Fork me on GitHub
#datomic
<
2021-02-01
>
ivana12:02:34

Hello! I have :region/city attribute with cardinality many and type string of :region entity in schema. Is there a way to change it on ref type with saving its id? I tried to change a type directly, add an aliase id->ident, both with and without clearing existing values - datomic rises an error everytime.

favila13:02:51

I think you’re asking if you can change :region/city to be ref instead of string typed? You cannot change the type of attributes. You can make a new attribute of the same name, but the old assertions will remain

favila13:02:27

I suggest for your sanity making a new attribute with a different name and working out your migration of old data to new. Only then consider changing names again; but with a large codebase it’s often just not worth it.

ivana13:02:40

I hide the details for make long story short - I created new attribute with new name & type and migrated all the data and cleared the values of old atttributes. But finally I need that old attribute name with new values.

ivana13:02:31

Now I have empty old attribute and fullfilled new but with different name

favila13:02:59

rename the string attribute to something else; then rename the ref attribute to :region/city

favila13:02:08

and make sure your code is ready for that, because ref and string are not compatible types

ivana13:02:59

What means "rename attribute"?

[[{:db/id          :region/cities
   :db/ident       :region/cities-old}
  {:db/id          :region/cities-ref
   :db/ident       :region/cities}]]

ivana13:02:23

ok, thanks, I'l try it. I thought I need to make a retractions from schema

favila13:02:05

you cannot retract attribute schema

favila13:02:19

you can only change idents around

ivana13:02:57

@U09R86PA4 thanks alot! Everything works and fine now, except little moment, that I have that old region attribute in schema without values )

favila13:02:22

well it does have values…in the past

ivana13:02:49

Ah, in the history