redarrowlabs / Argo

:squirrel: c# object => json.api relational mapping
MIT License
7 stars 3 forks source link

Support for in-place upgrades #88

Open zeitlerc opened 6 years ago

zeitlerc commented 6 years ago

Consider the scenario where the desired object structure changes:

The two main options are

  1. Run script to upgrade all objects at same time. Requires downtime during the upgrade since serializing/saving an non-upgraded object would cause data issues.
  2. In-place upgrade. V1 objects are transformed into V2 objects on read. Any saves will upgrade the object to V2 permanently. Upgrade scripts can be run during off-peak hours (so versions do not get too far behind).

For Argo to support in-place upgrades, it would need to:

[Model("person")]
public class PersonV1
{
    [Property]
    public string FullName { get; set; }
    [Property]
    public DateTime DateOfBirth { get; set; }
    // Other properties...
}
[Model("person")]
public class PersonV2
{
    [Property]
    public Identity Identity { get; set; }
    // Other properties...
}
public class Identity
{
    // Split FullName of V1 object into 3 components
    public string FirstName { get; set; }
    public string MiddleName { get;set; }
    public string LastName { get; set; }
    public DateTime DateOfBirth { get; set; } // Moved from root Person into Identity
    public Gender Gender { get; set; } // Default me to Gender.Unknown
}