I worked in a system which included a versioning system to migrate a DB to the latest version, and it worked like that. The only improvement we did, is that we sometimes wanted to avoid going through all versions, since it was a lengthly process, so you could define migrations from any version to any version
if you are in version 1.3 and want to migrate to the latest version and you have scripts to migrate from:
- 1.3 to 1.4
- 1.4 to 1.5
- 1.5 to 1.6
- 1.6 to 1.7
- 1.7 to 1.8
- 1.4 to 1.7
I'd detect automatically that it can use a single script to go over three versions 1.4 to 1.7 and use 1, 6 and 5. That's only worth it if the migration is lengthy though...
If you don't need to actually migrate the data, but just use it in the format of the latest version, you could achieve the same using the Adapter Pattern using object composition to transform an object with the "1.3" format to the "1.8" format using a chain of adapters in the middle.
In response to comment:
Sadly, we had to do the 1.4 to 1.7 by hand. You'll need something pretty smart to be able to compose optimized updates scripts from the individual ones, without executing them sequentially.