mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
Fix migration issue on invalid json char
This commit is contained in:
parent
222e8f66df
commit
c377617b5a
5 changed files with 13 additions and 13 deletions
|
@ -55,13 +55,14 @@ namespace BTCPayServer.Data
|
|||
};
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
public void Migrate()
|
||||
public bool TryMigrate()
|
||||
{
|
||||
if (Currency is not null)
|
||||
return;
|
||||
return false;
|
||||
if (Blob is not (null or { Length: 0 }))
|
||||
{
|
||||
Blob2 = MigrationExtensions.Unzip(Blob);
|
||||
Blob2 = MigrationExtensions.SanitizeJSON(Blob2);
|
||||
Blob = null;
|
||||
}
|
||||
var blob = JObject.Parse(Blob2);
|
||||
|
@ -349,10 +350,9 @@ namespace BTCPayServer.Data
|
|||
};
|
||||
blob["version"] = 3;
|
||||
Blob2 = blob.ToString(Formatting.None);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ShouldMigrate() => Currency is null;
|
||||
|
||||
[NotMapped]
|
||||
public bool Migrated { get; set; }
|
||||
static string[] detailsRemoveDefault =
|
||||
|
|
|
@ -147,5 +147,8 @@ namespace BTCPayServer.Data
|
|||
return $"{splitted[0]}-CHAIN";
|
||||
throw new NotSupportedException("Unknown payment id " + paymentMethodId);
|
||||
}
|
||||
|
||||
// Make postgres happy
|
||||
public static string SanitizeJSON(string json) => json.Replace("\\u0000", string.Empty, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,16 +17,14 @@ namespace BTCPayServer.Data
|
|||
{
|
||||
public interface IHasMigration
|
||||
{
|
||||
bool ShouldMigrate();
|
||||
void Migrate();
|
||||
bool TryMigrate();
|
||||
bool Migrated { get; set; }
|
||||
}
|
||||
public static readonly MigrationInterceptor Instance = new MigrationInterceptor();
|
||||
public object InitializedInstance(MaterializationInterceptionData materializationData, object entity)
|
||||
{
|
||||
if (entity is IHasMigration hasMigration && hasMigration.ShouldMigrate())
|
||||
if (entity is IHasMigration hasMigration && hasMigration.TryMigrate())
|
||||
{
|
||||
hasMigration.Migrate();
|
||||
hasMigration.Migrated = true;
|
||||
}
|
||||
return entity;
|
||||
|
|
|
@ -16,14 +16,15 @@ namespace BTCPayServer.Data
|
|||
{
|
||||
public partial class PaymentData : MigrationInterceptor.IHasMigration
|
||||
{
|
||||
public void Migrate()
|
||||
public bool TryMigrate()
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
if (Currency is not null)
|
||||
return;
|
||||
return false;
|
||||
if (Blob is not (null or { Length: 0 }))
|
||||
{
|
||||
Blob2 = MigrationExtensions.Unzip(Blob);
|
||||
Blob2 = MigrationExtensions.SanitizeJSON(Blob2);
|
||||
Blob = null;
|
||||
}
|
||||
var blob = JObject.Parse(Blob2);
|
||||
|
@ -158,9 +159,8 @@ namespace BTCPayServer.Data
|
|||
Blob2 = blob.ToString(Formatting.None);
|
||||
Accounted = null;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ShouldMigrate() => Currency is null;
|
||||
[NotMapped]
|
||||
public bool Migrated { get; set; }
|
||||
|
||||
|
|
|
@ -2835,7 +2835,6 @@ namespace BTCPayServer.Tests
|
|||
Assert.Equal("coingecko", b.PreferredExchange);
|
||||
}
|
||||
|
||||
|
||||
[Fact(Timeout = LongRunningTestTimeout)]
|
||||
[Trait("Integration", "Integration")]
|
||||
public async Task CanDoInvoiceMigrations()
|
||||
|
|
Loading…
Add table
Reference in a new issue