mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Fix: Crash during migration on some SQLite instances (Close #4623)
This commit is contained in:
@@ -220,6 +220,12 @@ namespace BTCPayServer.Hosting
|
|||||||
{
|
{
|
||||||
datetimeProperties.Add(col.PropertyMappings.Single().Property.PropertyInfo!);
|
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();
|
var rows = await query.ToListAsync();
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
{
|
{
|
||||||
@@ -239,6 +245,14 @@ namespace BTCPayServer.Hosting
|
|||||||
prop.SetValue(row, v.ToUniversalTime());
|
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;
|
postgresContext.Entry(row).State = EntityState.Added;
|
||||||
}
|
}
|
||||||
await postgresContext.SaveChangesAsync();
|
await postgresContext.SaveChangesAsync();
|
||||||
|
|||||||
Reference in New Issue
Block a user