Last Updated: February 25, 2016
·
2.233K
· yrashk

Upgrading records in Erlang / Elixir

It goes without saying that hot code upgrades are hard — first of all, it's just hard to plan one if your system is fairly complex.

However, there are a few pain points that, I believe, are unnecessarily hard or simply not obvious.

One example would be records (either Erlang or Elixir ones) — they are very often used to hold process state, etc. But once you load your new code, upgrading from a previous record becomes a pain — you either have to have a previous version of the record defined as a differently named record, or rely on some less explicit rules... needless to say, an obstacle that everybody would rather not have.

So I was thinking how to get rid of this problem and so far I think the only reasonably simple I can find is embedding record's version and structure into each and every instance of the record and providing conversion functionality between versions for anything more complex than a simple A -> A mapping.

I've got an hour of spare time on my lazy Saturday and got this done: https://github.com/yrashk/exrecord

By all means, no rocket science there. But I hate reimplementing half-assed strategies for just this. Wouldn't it be just nicer to have it implemented once and focus on harder problems?

Cheers.