diff --git a/BTCPayServer.Data/Data/MigrationExtensions.cs b/BTCPayServer.Data/Data/MigrationExtensions.cs index 08994038b..ab70668e4 100644 --- a/BTCPayServer.Data/Data/MigrationExtensions.cs +++ b/BTCPayServer.Data/Data/MigrationExtensions.cs @@ -147,6 +147,23 @@ namespace BTCPayServer.Data return $"{splitted[0]}-CHAIN"; throw new NotSupportedException("Unknown payment id " + paymentMethodId); } + public static string TryMigratePaymentMethodId(string paymentMethodId) + { + var splitted = paymentMethodId.Split(new[] { '_', '-' }); + if (splitted is [var cryptoCode, var paymentType]) + { + return paymentType switch + { + "BTCLike" => $"{cryptoCode}-CHAIN", + "LightningLike" or "LightningNetwork" => $"{cryptoCode}-LN", + "LNURLPAY" => $"{cryptoCode}-LNURL", + _ => paymentMethodId + }; + } + if (splitted.Length == 1) + return $"{splitted[0]}-CHAIN"; + return paymentMethodId; + } // Make postgres happy public static string SanitizeJSON(string json) => json.Replace("\\u0000", string.Empty, StringComparison.OrdinalIgnoreCase); diff --git a/BTCPayServer/Hosting/MigrationStartupTask.cs b/BTCPayServer/Hosting/MigrationStartupTask.cs index 1b906ace9..c6b1a35e1 100644 --- a/BTCPayServer/Hosting/MigrationStartupTask.cs +++ b/BTCPayServer/Hosting/MigrationStartupTask.cs @@ -233,6 +233,12 @@ namespace BTCPayServer.Hosting private async Task MigrateStoreExcludedPaymentMethods() { + HashSet oldPaymentIds = new() + { + "LightningLike", + "BTCLike", + "LNURLPAY" + }; await using var ctx = _DBContextFactory.CreateContext(); var stores = await ctx.Stores.ToArrayAsync(); foreach (var store in stores) @@ -243,8 +249,7 @@ namespace BTCPayServer.Hosting var array = blob["excludedPaymentMethods"] as JArray; if (array is null || array.Count == 0) continue; - var newArray = new JArray(array.Select(a => MigrationExtensions.MigratePaymentMethodId(a.Value())) - .ToArray()); + var newArray = new JArray(array.Select(a => MigrationExtensions.TryMigratePaymentMethodId(a.Value())).ToArray()); if (array.ToString() == newArray.ToString()) continue; blob["excludedPaymentMethods"] = newArray;