XML file migration concept using F# XML type provider.
Sometimes it is enough to store data in a simple XML file by serializing an object instead of using 'professional' database (especially when concurrent access is not required and when the database is not very big). The problem appears, when after changing the model in our code, an XML file (our database) remains 'old' (corresponds to previous object definition). For example we have changed 'Description' property to 'Desc' of the Customer class or we have added 'Address' property to our Customer class. We can't deserialize old XML file using new model, because there is no 'Description' neither 'Address' properties in our current model. In order to make our old XML data working with new model we have to migrate XML file. There are many approaches allowing to achieve this goal, one of which is the usage of FSharp XML Type Provider.
This project shows a very simple concept of migrating existing 'XML database' based on:
- migration concept widely used in EntityFramework Code First (based on __MigrationHistory table)
- FSharp XML Type Provider
- FsXmlMigration.Domain.Cs - models and repositories (serializers)
- FsXmlMigration.Lib.Fs - migration library (XML Type Provider used to manipulate 'old' XML strongly typed data)
- FsXmlMigration.App.Fs - simple F# app which initializes database and executes migrations
- FsXmlMigration.App.Cs - simple C# app which initializes database and executes migrations
- .NET Framework 4.6.1
- Visual Studio 2017 15.4.1 (or above)
- Set breakpoint in Migrator.fs file (line 29)
- Debug FsXmlMigration.App.Fs app (or FsXmlMigration.App.Cs)
- Observe 'Database\Customers.xml' and 'Database\MigrationHistory.xml' changes each time breakpoint stops the app