I work in a SaaS project in which each user can have a representation of some common data at a given point in time. For the sake of example, let's consider that each user's data is metadata about them persisted separately on disk as a JSON file:
{
"name" : "Bob"
}
As new requirements come along, this underlying representation may change (for example, in the above JSON, let's say that name attribute is changed to firstName
and another attribute lastName
is added). In order to support artifacts that were created at different points in time, we are forced to handle this in one of two ways:
- Migrate all data from old representation to new
- Follow different code paths/conditional logic depending on underlying representation:
.
if (oldRepresentation) {
... do this ...
} else if (middleRepresentation) {
... do that ...
} else {
... do something else ...
}
Both seem problematic in that one is a big bang approach (and we all know that migrations are rarely smooth) and the other creates some amount of dissonance in the source with all the conditional logic. I'm curious how other projects handle migrations of this sort? Do most of you use one of the above approaches? How does your architecture account for this? Do you have a separate service to do migrations on demand?