From 5d547fed19a42c715f243fd6e918e76552626317 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Mon, 13 Nov 2023 12:05:37 +0100 Subject: [PATCH] Raise default PG compat version to 14 Closes #1645 --- .../Infrastructure/Internal/NpgsqlOptionsExtension.cs | 2 +- .../Internal/NpgsqlMemberTranslatorProvider.cs | 3 +-- .../Internal/NpgsqlMethodCallTranslatorProvider.cs | 3 +-- src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs | 4 +--- test/EFCore.PG.FunctionalTests/DefaultValuesTest.cs | 6 ++++-- .../Migrations/MigrationsInfrastructureNpgsqlTest.cs | 8 +++++++- test/EFCore.PG.FunctionalTests/SpatialNpgsqlFixture.cs | 4 +++- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs b/src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs index 3bb02b293..6df6c4cbd 100644 --- a/src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs +++ b/src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs @@ -22,7 +22,7 @@ public class NpgsqlOptionsExtension : RelationalOptionsExtension /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public static readonly Version DefaultPostgresVersion = new(12, 0); + public static readonly Version DefaultPostgresVersion = new(14, 0); /// /// The backend version to target. diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMemberTranslatorProvider.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMemberTranslatorProvider.cs index ed4159dc4..bf6baa16e 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMemberTranslatorProvider.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMemberTranslatorProvider.cs @@ -29,8 +29,7 @@ public NpgsqlMemberTranslatorProvider( : base(dependencies) { var npgsqlOptions = contextOptions.FindExtension() ?? new(); - var supportsMultiranges = !npgsqlOptions.IsPostgresVersionSet - || npgsqlOptions.IsPostgresVersionSet && npgsqlOptions.PostgresVersion.AtLeast(14); + var supportsMultiranges = npgsqlOptions.PostgresVersion.AtLeast(14); var sqlExpressionFactory = (NpgsqlSqlExpressionFactory)dependencies.SqlExpressionFactory; JsonPocoTranslator = new NpgsqlJsonPocoTranslator(typeMappingSource, sqlExpressionFactory, model); diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMethodCallTranslatorProvider.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMethodCallTranslatorProvider.cs index 2a82c7a6d..8e1e9eb5a 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMethodCallTranslatorProvider.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMethodCallTranslatorProvider.cs @@ -32,8 +32,7 @@ public NpgsqlMethodCallTranslatorProvider( : base(dependencies) { var npgsqlOptions = contextOptions.FindExtension() ?? new(); - var supportsMultiranges = !npgsqlOptions.IsPostgresVersionSet - || npgsqlOptions.IsPostgresVersionSet && npgsqlOptions.PostgresVersion.AtLeast(14); + var supportsMultiranges = npgsqlOptions.PostgresVersion.AtLeast(14); var sqlExpressionFactory = (NpgsqlSqlExpressionFactory)dependencies.SqlExpressionFactory; var typeMappingSource = (NpgsqlTypeMappingSource)dependencies.RelationalTypeMappingSource; diff --git a/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs b/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs index 37054d116..a7f9b9fe7 100644 --- a/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs +++ b/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs @@ -191,9 +191,7 @@ public NpgsqlTypeMappingSource( INpgsqlSingletonOptions options) : base(dependencies, relationalDependencies) { - _supportsMultiranges = !options.IsPostgresVersionSet - || options.IsPostgresVersionSet && options.PostgresVersion.AtLeast(14); - + _supportsMultiranges = options.PostgresVersion.AtLeast(14); _sqlGenerationHelper = Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper)); // Initialize range mappings, which reference on other mappings diff --git a/test/EFCore.PG.FunctionalTests/DefaultValuesTest.cs b/test/EFCore.PG.FunctionalTests/DefaultValuesTest.cs index 003d668d8..415293c8f 100644 --- a/test/EFCore.PG.FunctionalTests/DefaultValuesTest.cs +++ b/test/EFCore.PG.FunctionalTests/DefaultValuesTest.cs @@ -56,7 +56,9 @@ public ChipsContext(IServiceProvider serviceProvider, string databaseName) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder - .UseNpgsql(NpgsqlTestStore.CreateConnectionString(_databaseName)) + .UseNpgsql( + NpgsqlTestStore.CreateConnectionString(_databaseName), + o => o.SetPostgresVersion(TestEnvironment.PostgresVersion)) .UseInternalServiceProvider(_serviceProvider); protected override void OnModelCreating(ModelBuilder modelBuilder) @@ -73,4 +75,4 @@ private class KettleChips public string Name { get; set; } public DateTime BestBuyDate { get; set; } } -} \ No newline at end of file +} diff --git a/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs index 7c3e8d519..089ddc598 100644 --- a/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs @@ -150,11 +150,17 @@ public override MigrationsContext CreateContext() new DbContextOptionsBuilder() .UseNpgsql(TestStore.ConnectionString, b => b.ApplyConfiguration() .CommandTimeout(NpgsqlTestStore.CommandTimeout) + .SetPostgresVersion(TestEnvironment.PostgresVersion) .ReverseNullOrdering())) - .UseInternalServiceProvider(ServiceProvider) + .UseInternalServiceProvider(CreateServiceProvider()) .Options; return new MigrationsContext(options); } + + private static IServiceProvider CreateServiceProvider() + => new ServiceCollection() + .AddEntityFrameworkNpgsql() + .BuildServiceProvider(); } } } diff --git a/test/EFCore.PG.FunctionalTests/SpatialNpgsqlFixture.cs b/test/EFCore.PG.FunctionalTests/SpatialNpgsqlFixture.cs index a172d63e8..cf6c900e3 100644 --- a/test/EFCore.PG.FunctionalTests/SpatialNpgsqlFixture.cs +++ b/test/EFCore.PG.FunctionalTests/SpatialNpgsqlFixture.cs @@ -22,7 +22,9 @@ protected override IServiceCollection AddServices(IServiceCollection serviceColl public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) { var optionsBuilder = base.AddOptions(builder); - new NpgsqlDbContextOptionsBuilder(optionsBuilder).UseNetTopologySuite(); + new NpgsqlDbContextOptionsBuilder(optionsBuilder) + .UseNetTopologySuite() + .SetPostgresVersion(TestEnvironment.PostgresVersion); return optionsBuilder; }