[chore:] Schema version 4
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Logof_Client;
|
||||
|
||||
@@ -12,7 +13,7 @@ namespace Logof_Client;
|
||||
public static class SchemaMigration
|
||||
{
|
||||
// Current schema version - increment when you make breaking changes
|
||||
public const int CURRENT_SCHEMA_VERSION = 3;
|
||||
public const int CURRENT_SCHEMA_VERSION = 4;
|
||||
|
||||
// Dictionary of migration functions, keyed by the version they migrate TO
|
||||
private static readonly Dictionary<int, Func<JObject, JObject>> Migrations = new()
|
||||
@@ -22,7 +23,7 @@ public static class SchemaMigration
|
||||
// { 2, MigrateV1ToV2 },
|
||||
|
||||
// Example: Migration from v2 to v3
|
||||
// { 3, MigrateV2ToV3 },
|
||||
{ 4, MigrateV3ToV4 },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -93,12 +94,13 @@ public static class SchemaMigration
|
||||
/// Example migration function: from v2 to v3.
|
||||
/// Add a new required field with a default value.
|
||||
/// </summary>
|
||||
private static JObject MigrateV2ToV3(JObject obj)
|
||||
private static JObject MigrateV3ToV4(JObject obj)
|
||||
{
|
||||
// Example: Add a new field that didn't exist before
|
||||
if (!obj.ContainsKey("new_required_field"))
|
||||
if (!obj.ContainsKey("moduleConfig"))
|
||||
{
|
||||
obj["new_required_field"] = "default_value";
|
||||
string deflt = JsonConvert.SerializeObject(new ModuleConfig());
|
||||
obj["moduleConfig"] = default;
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
||||
Reference in New Issue
Block a user