10

Is anybody aware of any design patterns around software updates? Specifically I'd like a pattern for converting old files/settings into the latest version.

The best solution I can think of would be to have a set of rules for how to convert from each version to the next version (e.g. v1.0 to v1.1, v1.1 to v1.2, ...). Then to convert files/settings to the latest version you would run all the conversion rules in order.

This doesn't strike me as a very elegant way of doing things - is there a better way?

stormCloud
  • 983
  • 1
  • 9
  • 24
  • 2
    Don't let your worry about elegance fool you -- your solution is the best one. Trying to shortcut the problem and be more "elegant" actually just creates duplication. – tallseth Jul 09 '12 at 04:04

1 Answers1

5

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. 1.3 to 1.4
  2. 1.4 to 1.5
  3. 1.5 to 1.6
  4. 1.6 to 1.7
  5. 1.7 to 1.8
  6. 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.

user1494736
  • 2,425
  • 16
  • 8
  • +1, thanks for the answer. When you created the script from v1.4 to v1.7, did you do it by hand, or did you use an automated tool to do it, as it strikes me as the sort of thing that a code optimiser from a compiler would be good at. – stormCloud Jul 09 '12 at 15:46