Browse Source

[SM-412] Remove postgres timezone legacy behavior (#2547)

pull/2559/head
Oscar Hinton 3 years ago committed by GitHub
parent
commit
b1dfbe7519
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .config/dotnet-tools.json
  2. 18
      src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs
  3. 3
      util/PostgresMigrations/Factories.cs

4
.config/dotnet-tools.json

@ -21,10 +21,10 @@ @@ -21,10 +21,10 @@
]
},
"dotnet-ef": {
"version": "6.0.11",
"version": "6.0.12",
"commands": [
"dotnet-ef"
]
}
}
}
}

18
src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs

@ -157,20 +157,10 @@ public class DatabaseContext : DbContext @@ -157,20 +157,10 @@ public class DatabaseContext : DbContext
{
if (property.ClrType == typeof(DateTime) || property.ClrType == typeof(DateTime?))
{
if (Database.IsNpgsql())
{
property.SetValueConverter(
new ValueConverter<DateTime, DateTime>(
v => v,
v => v.ToUniversalTime()));
}
else
{
property.SetValueConverter(
new ValueConverter<DateTime, DateTime>(
v => v,
v => new DateTime(v.Ticks, DateTimeKind.Utc)));
}
property.SetValueConverter(
new ValueConverter<DateTime, DateTime>(
v => v,
v => new DateTime(v.Ticks, DateTimeKind.Utc)));
}
}
}

3
util/PostgresMigrations/Factories.cs

@ -25,9 +25,6 @@ public class DatabaseContextFactory : IDesignTimeDbContextFactory<DatabaseContex @@ -25,9 +25,6 @@ public class DatabaseContextFactory : IDesignTimeDbContextFactory<DatabaseContex
var globalSettings = GlobalSettingsFactory.GlobalSettings;
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
var connectionString = globalSettings.PostgreSql?.ConnectionString;
// NpgSql 6.0 changed how timezones works. We have not yet updated our projects to support this new behavior and need to fallback to the previous behavior.
// Check https://www.npgsql.org/doc/release-notes/6.0.html#timestamp-rationalization-and-improvements for more details.
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new Exception("No Postgres connection string found.");

Loading…
Cancel
Save