Search code examples
csvcsvhelper

Versioning Objects written to CSV


I am currently working on converting objects to csv and back again. I have come to a point where I need to consider how versioning would work. The current library I am utilizing is CsvHelper

For example it is common in our business area for requirements to change after production release so initially an object storing GPS LAT and GPS LONG can be extended after a period of production use to have NumberOfSatellites as a contrived case.

This means that there are files written out initially with the first format ; lat,long as V1 and now a V2 with NumberOfSatellites. Ideally, this original data should be able to be read by the V2 object for testing and backwards compatibility.

Again, if a property is no longer required such as NumberOfSatellites in a V3 , the data produced by V1 and V2 should still be valid or should it not?

Lastly what happens in the event of a change of name of property, for example GPS LAT is renamed to LATITUDE. The data in V1,V2 and V3 should hopefully still be valid to be read.

How do others get around these issues? Or am I expecting too much from the CSV format


Solution

  • This is an issue with any stored data and that data changing.

    What you need to do is have different versions of your classes for each version of the data. You then need to have upgrade code between each version. If something is on version 1 and the current version is 3, then you need to run it through the code that upgrade from 1->2 and then from 2->3.

    To keep it organized, you can have your normal classes that are always up to date. Then you can have an upgrade folder that contains folders for each version. In there you can have the old versions of each file, along with the upgrade code, and the csv mapping files, and anything else that went along with the old code.