Fix: Crash during migration on some SQLite instances (Close #4623)

This commit is contained in:
nicolas.dorier 2023-02-22 17:07:27 +09:00
parent a02f191034
commit 02e50fadae
No known key found for this signature in database
GPG key ID: 6618763EF09186FE

View file

@ -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();