datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
2021-02-01T12:22:34.086500Z

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.

favila 2021-02-01T13:10:51.087700Z

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

favila 2021-02-01T13:12:27.087900Z

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.

2021-02-01T13:15:40.088200Z

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.

2021-02-01T13:16:31.088400Z

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

favila 2021-02-01T13:17:59.088700Z

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

favila 2021-02-01T13:19:08.088900Z

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

2021-02-01T13:20:59.089100Z

What means "rename attribute"?

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

2021-02-01T13:21:02.089300Z

?

favila 2021-02-01T13:21:33.089500Z

yes

2021-02-01T13:22:23.089700Z

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

favila 2021-02-01T13:23:05.089900Z

you cannot retract attribute schema

favila 2021-02-01T13:23:19.090100Z

you can only change idents around

2021-02-01T13:55:57.090300Z

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

favila 2021-02-01T13:56:22.090500Z

well it does have values…in the past

2021-02-01T13:56:49.090700Z

Ah, in the history