Fix: Migration bug on old instances (Could not cast or convert from System.String to BTCPayServer.DerivationSchemeSettings) (#6551)

This commit is contained in:
Nicolas Dorier 2025-01-15 23:06:17 +09:00 committed by GitHub
parent 2250853b3e
commit e479522d9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -224,6 +224,12 @@ namespace BTCPayServer.Hosting
settings.MigrateStoreExcludedPaymentMethods = true;
await _Settings.UpdateSetting(settings);
}
if (!settings.MigrateOldDerivationSchemes)
{
await MigrateOldDerivationSchemes();
settings.MigrateOldDerivationSchemes = true;
await _Settings.UpdateSetting(settings);
}
}
catch (Exception ex)
{
@ -232,6 +238,31 @@ namespace BTCPayServer.Hosting
}
}
private async Task MigrateOldDerivationSchemes()
{
await using var ctx = _DBContextFactory.CreateContext();
var stores = await ctx.Stores.ToArrayAsync();
foreach (var store in stores)
{
if (string.IsNullOrEmpty(store.DerivationStrategies))
continue;
JObject strategies = JObject.Parse(store.DerivationStrategies);
if (strategies is null)
continue;
foreach (var prop in strategies.Properties())
{
var h = _handlers.TryGet(new PaymentMethodId(prop.Name));
if (h is not BitcoinLikePaymentHandler bh ||
prop.Value is not JValue { Type: JTokenType.String, Value: string v })
continue;
var settings = DerivationSchemeSettings.Parse(v, bh.Network);
prop.Value = JToken.FromObject(settings, bh.Serializer);
store.DerivationStrategies = strategies.ToString();
}
}
await ctx.SaveChangesAsync();
}
private async Task MigrateStoreExcludedPaymentMethods()
{
await using var ctx = _DBContextFactory.CreateContext();

View File

@ -32,6 +32,7 @@ namespace BTCPayServer.Services
public bool MigrateAppYmlToJson { get; set; }
public bool MigrateToStoreConfig { get; set; }
public bool MigrateBlockExplorerLinks { get; set; }
public bool MigrateStoreExcludedPaymentMethods { get; internal set; }
public bool MigrateStoreExcludedPaymentMethods { get; set; }
public bool MigrateOldDerivationSchemes { get; set; }
}
}