Merge pull request #5902 from btcpayserver/fweoinqrnt

Fix migration crash
This commit is contained in:
Nicolas Dorier 2024-04-04 23:11:21 +09:00 committed by GitHub
commit ff5e03a8b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 14 additions and 15 deletions

View File

@ -14,6 +14,7 @@ using Newtonsoft.Json;
using Microsoft.EntityFrameworkCore.Diagnostics;
using BTCPayServer.Migrations;
using Newtonsoft.Json.Serialization;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
namespace BTCPayServer.Data
{
@ -28,11 +29,11 @@ namespace BTCPayServer.Data
public static readonly MigrationInterceptor Instance = new MigrationInterceptor();
public object InitializedInstance(MaterializationInterceptionData materializationData, object entity)
{
if (entity is InvoiceData invoiceData)
if (entity is InvoiceData invoiceData && invoiceData.Currency is null)
{
invoiceData.Migrate();
}
else if (entity is PaymentData paymentData)
else if (entity is PaymentData paymentData && paymentData.Currency is null)
{
paymentData.Migrate();
}
@ -65,7 +66,8 @@ namespace BTCPayServer.Data
"derivationStrategy",
"archived",
"isUnderPaid",
"requiresRefundEmail"
"requiresRefundEmail",
"invoiceTime"
};
#pragma warning disable CS0618 // Type or member is obsolete
@ -73,13 +75,13 @@ namespace BTCPayServer.Data
{
if (Currency is not null)
return;
if (Blob is not null)
if (Blob is not (null or { Length: 0 }))
{
Blob2 = MigrationExtensions.Unzip(Blob);
Blob = null;
}
var blob = JObject.Parse(Blob2);
if (blob["cryptoData"]?["BTC"] is not null)
if (blob["cryptoData"]?["BTC"] is not (null or { Type: JTokenType.Null }))
{
blob.Move(["rate"], ["cryptoData", "BTC", "rate"]);
blob.Move(["txFee"], ["cryptoData", "BTC", "txFee"]);
@ -280,7 +282,7 @@ namespace BTCPayServer.Data
var divisibility = MigrationExtensions.GetDivisibility(prop.Name);
prompt.Add("divisibility", divisibility);
if (prompt["paymentMethodFee"] is { } paymentMethodFee)
if (prompt["paymentMethodFee"] is { Type: JTokenType.Integer } paymentMethodFee)
{
prompt["paymentMethodFee"] = ((decimal)paymentMethodFee.Value<long>() / (decimal)Math.Pow(10, divisibility)).ToString(CultureInfo.InvariantCulture);
prompt.RemoveIfValue<string>("paymentMethodFee", "0");
@ -304,7 +306,7 @@ namespace BTCPayServer.Data
var details = prompt["details"] as JObject ?? new JObject();
details.RemoveIfValue<bool>("payjoinEnabled", false);
details.RemoveIfNull("feeMode");
if (details["feeMode"] is not null)
if (details["feeMode"] is not (null or { Type: JTokenType.Null }))
{
details["feeMode"] = details["feeMode"].Value<int>() switch
{
@ -341,7 +343,7 @@ namespace BTCPayServer.Data
}
}
if (blob["defaultPaymentMethod"] is not null)
if (blob["defaultPaymentMethod"] is not (null or { Type : JTokenType.Null }))
blob["defaultPaymentMethod"] = MigrationExtensions.MigratePaymentMethodId(blob["defaultPaymentMethod"].Value<string>());
blob.Remove("derivationStrategies");

View File

@ -20,7 +20,7 @@ namespace BTCPayServer.Data
#pragma warning disable CS0618 // Type or member is obsolete
if (Currency is not null)
return;
if (Blob is not null)
if (Blob is not (null or { Length: 0 }))
{
Blob2 = MigrationExtensions.Unzip(Blob);
Blob = null;

View File

@ -82,7 +82,6 @@
"destination": "39mWwvUDoZ5CxXa6CmgaUda19qYj9LpQD1"
}
},
"invoiceTime": 1538395793,
"redirectURL": "https://example.com/thanksyou",
"receiptOptions": {},
"internalTags": [],
@ -202,7 +201,6 @@
}
},
"receiptOptions": {},
"invoiceTime": 1709806449,
"redirectURL": "https://test/",
"speedPolicy": 1,
"internalTags": [],
@ -437,7 +435,6 @@
"details": {}
}
},
"invoiceTime": 1709864059,
"speedPolicy": 1,
"expirationTime": 1709864959,
"receiptOptions": {},
@ -574,7 +571,6 @@
}
}
},
"invoiceTime": 1697828706,
"speedPolicy": 1,
"internalTags": [],
"expirationTime": 1697829606,

View File

@ -21,6 +21,7 @@ namespace BTCPayServer.Data
{
if (blob.Metadata is null)
blob.Metadata = new InvoiceMetadata();
invoiceData.Created = blob.InvoiceTime;
invoiceData.Currency = blob.Currency;
invoiceData.Amount = blob.Price;
invoiceData.HasTypedBlob<InvoiceEntity>().SetBlob(blob, DefaultSerializer);
@ -41,7 +42,7 @@ namespace BTCPayServer.Data
{
entity.Price = price;
}
entity.InvoiceTime = invoiceData.Created;
entity.StoreId = invoiceData.StoreDataId;
entity.ExceptionStatus = state.ExceptionStatus;
entity.Status = state.Status;

View File

@ -277,6 +277,7 @@ namespace BTCPayServer.Services.Invoices
public SpeedPolicy SpeedPolicy { get; set; }
[JsonProperty]
public string DefaultLanguage { get; set; }
[JsonIgnore]
public DateTimeOffset InvoiceTime { get; set; }
public DateTimeOffset ExpirationTime { get; set; }
public InvoiceMetadata Metadata { get; set; }

View File

@ -228,7 +228,6 @@ namespace BTCPayServer.Services.Invoices
{
StoreDataId = invoice.StoreId,
Id = invoice.Id,
Created = invoice.InvoiceTime,
OrderId = invoice.Metadata.OrderId,
#pragma warning disable CS0618 // Type or member is obsolete
Status = invoice.StatusString,