From b726ef8a2e52b915d5c10a2141963e45aab2ff4d Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 24 Sep 2024 09:43:02 +0900 Subject: [PATCH] Migrate PayoutProcessors's PayoutMethodId in entity migration --- .../Migrations/20240906010127_renamecol.cs | 9 +++++++++ BTCPayServer/Hosting/MigrationStartupTask.cs | 17 ----------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/BTCPayServer.Data/Migrations/20240906010127_renamecol.cs b/BTCPayServer.Data/Migrations/20240906010127_renamecol.cs index 1e698a9b9..0394f1bb1 100644 --- a/BTCPayServer.Data/Migrations/20240906010127_renamecol.cs +++ b/BTCPayServer.Data/Migrations/20240906010127_renamecol.cs @@ -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; + """); } /// diff --git a/BTCPayServer/Hosting/MigrationStartupTask.cs b/BTCPayServer/Hosting/MigrationStartupTask.cs index 27201ba8b..cdec5e1a1 100644 --- a/BTCPayServer/Hosting/MigrationStartupTask.cs +++ b/BTCPayServer/Hosting/MigrationStartupTask.cs @@ -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();