Qqwy
December 25, 2018, 5:51pm
5
It’s interesting to note that in Haskell, there is a library to facilitate upgradable types, called SafeCopy , which is used in some systems, but it does not seem to be entirely painless:
From user ‘Mightybyte’ on the Haskell ∪ Chat Discord group:
@Qqwy The safecopy approach can be a little cumbersome to use in practice.
Its migration requires you to define a function migrate :: a -> b
Data.SafeCopy
This means that if you add a new field to your Person data type, you have to keep the old Person data type around.
In practice, the easiest way for me to do this was to create a module Person.V1 where I put the old code.
Then migrate :: Person.V1.Person -> Person
At first glance the approach seemed nice to me, but after using it for awhile with larger production data types, it got pretty painful.
If you think of this problem as a graph where the nodes of the graph are your data types and the edges of the graph are migrations between different versions, I call this safecopy approach the node-oriented approach. You have to keep around all the nodes.
The other approach is what I call the edge-oriented approach, which is where you don’t store multiple versions of the data types, but rather you store code that performs the migration. [which would not use SafeCopy, but e.g. migration logic in plain SQL, and assumes that your data structures are all at rest when migrating.]
1 Like