mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
Fix: Crash during migration on some SQLite instances (Close #4623)
This commit is contained in:
parent
a02f191034
commit
02e50fadae
1 changed files with 14 additions and 0 deletions
|
@ -220,6 +220,12 @@ namespace BTCPayServer.Hosting
|
|||
{
|
||||
datetimeProperties.Add(col.PropertyMappings.Single().Property.PropertyInfo!);
|
||||
}
|
||||
List<PropertyInfo> datetimeoffsetProperties = new List<PropertyInfo>();
|
||||
foreach (var col in t.Columns)
|
||||
if (col.PropertyMappings.Single().Property.ClrType == typeof(DateTimeOffset))
|
||||
{
|
||||
datetimeoffsetProperties.Add(col.PropertyMappings.Single().Property.PropertyInfo!);
|
||||
}
|
||||
var rows = await query.ToListAsync();
|
||||
foreach (var row in rows)
|
||||
{
|
||||
|
@ -239,6 +245,14 @@ namespace BTCPayServer.Hosting
|
|||
prop.SetValue(row, v.ToUniversalTime());
|
||||
}
|
||||
}
|
||||
foreach (var prop in datetimeoffsetProperties)
|
||||
{
|
||||
var v = (DateTimeOffset)prop.GetValue(row)!;
|
||||
if (v.Offset != TimeSpan.Zero)
|
||||
{
|
||||
prop.SetValue(row, v.ToOffset(TimeSpan.Zero));
|
||||
}
|
||||
}
|
||||
postgresContext.Entry(row).State = EntityState.Added;
|
||||
}
|
||||
await postgresContext.SaveChangesAsync();
|
||||
|
|
Loading…
Add table
Reference in a new issue