Let’s pretend our database has recorded two attributes for a user. The user’s e-mail and the users username.
The username is required to be the e-mail for the user. Due to a design decision, e-mails will no longer
be recorded. As such we need to depricate the e-mail attribute and merge it to our username attribute to ensure
all e-mails represent usernames.
The steps to this process are as follows:
Rename the old attribute (i.e. :user/email to :user/email-deprecated)
Make the new attribute (:user/username)
Migrate values from the old attribute to the new attribute
It should be noted that if you have a lot of data to merge you will want to appropriately batch the
merge transactions. This is also not a solution for bad schema design and it should not be relied upon
to correct what are in reality schema design problems. d/history will still point to the previous entry
and :db/ident is not t-aware.
Please see Stu Halloways blog post http://blog.datomic.com/2017/01/the-ten-rules-of-schema-growth.html
Show me how to merge, baby
slurp in the schema.edn file which contains:
Pull the attributes I have inserted.
Transact some data against e-mails and usernames. We will then merge this data. Here are the contents of Data.edn which will be slurped
And there you have it, you’ve merged all the usernames under one attribute!!!!
Fulltext happens
This process can be applied when needing to implement :db/fulltext. But instead of altering existing
schema we need to add a new attribute and transact with fulltext enabled. We will then want to pour in/import our data and use the new attribute going forward