Migrate PayoutProcessors's PayoutMethodId in entity migration

This commit is contained in:
nicolas.dorier 2024-09-24 09:43:02 +09:00
parent 25e360e175
commit b726ef8a2e
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
2 changed files with 9 additions and 17 deletions

View file

@ -26,6 +26,15 @@ namespace BTCPayServer.Migrations
name: "PaymentMethod",
table: "PayoutProcessors",
newName: "PayoutMethodId");
migrationBuilder.Sql("""
UPDATE "PayoutProcessors"
SET
"PaymentMethodId" = CASE WHEN STRPOS("PaymentMethodId", '_') = 0 THEN "PaymentMethodId" || '-CHAIN'
CASE WHEN STRPOS("PaymentMethodId", '_LightningLike') = 0 THEN "PaymentMethodId" || '-LN'
CASE WHEN STRPOS("PaymentMethodId", '_LNURLPAY') = 0 THEN "PaymentMethodId" || '-LN'
ELSE "PaymentMethodId" END;
""");
}
/// <inheritdoc />

View file

@ -211,12 +211,6 @@ namespace BTCPayServer.Hosting
settings.MigrateToStoreConfig = true;
await _Settings.UpdateSetting(settings);
}
if (!settings.MigratePayoutProcessors)
{
await MigratePayoutProcessors();
settings.MigratePayoutProcessors = true;
await _Settings.UpdateSetting(settings);
}
}
catch (Exception ex)
{
@ -225,17 +219,6 @@ namespace BTCPayServer.Hosting
}
}
private async Task MigratePayoutProcessors()
{
await using var ctx = _DBContextFactory.CreateContext();
var processors = await ctx.PayoutProcessors.ToArrayAsync();
foreach (var processor in processors)
{
processor.PayoutMethodId = processor.GetPayoutMethodId().ToString();
}
await ctx.SaveChangesAsync();
}
private async Task MigrateToStoreConfig()
{
await using var ctx = _DBContextFactory.CreateContext();