Skip to content

Commit

Permalink
Sync to EF Core 9.0.0-rc.1.24451.1
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Sep 2, 2024
1 parent 318c46c commit c150540
Show file tree
Hide file tree
Showing 19 changed files with 245 additions and 120 deletions.
15 changes: 8 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<EFCoreVersion>[9.0.0-preview.7.24405.3]</EFCoreVersion>
<MicrosoftExtensionsVersion>9.0.0-preview.7.24405.7</MicrosoftExtensionsVersion>
<EFCoreVersion>[9.0.0-rc.1.24451.1]</EFCoreVersion>
<MicrosoftExtensionsVersion>9.0.0-rc.1.24431.7</MicrosoftExtensionsVersion>
<NpgsqlVersion>8.0.3</NpgsqlVersion>
</PropertyGroup>

Expand All @@ -21,15 +21,16 @@
<PackageVersion Include="Npgsql.NetTopologySuite" Version="$(NpgsqlVersion)" />
<PackageVersion Include="Npgsql.DependencyInjection" Version="$(NpgsqlVersion)" />

<!-- Workaround for unsecure dependency on EF.Specification.Tests -->
<!-- Workaround for unsecure dependencies in EF -->
<PackageVersion Include="System.Formats.Asn1" Version="8.0.1" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />

<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="xunit" Version="2.8.1" />
<PackageVersion Include="xunit.assert" Version="2.8.1" />
<PackageVersion Include="xunit.core" Version="2.8.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.assert" Version="2.9.0" />
<PackageVersion Include="xunit.core" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.100-preview.7.24407.12",
"version": "9.0.100-rc.1.24451.4",
"rollForward": "latestMajor",
"allowPrerelease": true
}
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.PG/Migrations/Internal/NpgsqlHistoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ await Dependencies.RawSqlCommandBuilder.Build(ExistsSql).ExecuteScalarAsync(
/// 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.
/// </summary>
public override IDisposable GetDatabaseLock(TimeSpan timeout)
public override IDisposable GetDatabaseLock()
{
// TODO: There are issues with the current lock implementation in EF - most importantly, the lock isn't acquired within a
// transaction so we can't use e.g. LOCK TABLE. This should be fixed for rc.1, see #34439.
Expand All @@ -81,7 +81,7 @@ public override IDisposable GetDatabaseLock(TimeSpan timeout)
/// 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.
/// </summary>
public override Task<IAsyncDisposable> GetDatabaseLockAsync(TimeSpan timeout, CancellationToken cancellationToken = default)
public override Task<IAsyncDisposable> GetDatabaseLockAsync(CancellationToken cancellationToken = default)
{
// TODO: There are issues with the current lock implementation in EF - most importantly, the lock isn't acquired within a
// transaction so we can't use e.g. LOCK TABLE. This should be fixed for rc.1, see #34439.
Expand Down
29 changes: 13 additions & 16 deletions src/EFCore.PG/Migrations/Internal/NpgsqlMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ public NpgsqlMigrator(
IModelRuntimeInitializer modelRuntimeInitializer,
IDiagnosticsLogger<DbLoggerCategory.Migrations> logger,
IRelationalCommandDiagnosticsLogger commandLogger,
IDatabaseProvider databaseProvider)
IDatabaseProvider databaseProvider,
IMigrationsModelDiffer migrationsModelDiffer,
IDesignTimeModel designTimeModel,
IDbContextOptions contextOptions)
: base(migrationsAssembly, historyRepository, databaseCreator, migrationsSqlGenerator, rawSqlCommandBuilder,
migrationCommandExecutor, connection, sqlGenerationHelper, currentContext, modelRuntimeInitializer, logger,
commandLogger, databaseProvider)
commandLogger, databaseProvider, migrationsModelDiffer, designTimeModel, contextOptions)
{
_historyRepository = historyRepository;
_connection = connection;
Expand All @@ -51,7 +54,7 @@ public NpgsqlMigrator(
/// 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.
/// </summary>
public override void Migrate(string? targetMigration = null)
public override void Migrate(string? targetMigration)
{
var appliedMigrations = _historyRepository.GetAppliedMigrations();

Expand All @@ -60,17 +63,15 @@ public override void Migrate(string? targetMigration = null)
PopulateMigrations(
appliedMigrations.Select(t => t.MigrationId),
targetMigration,
out var migrationsToApply,
out var migrationsToRevert,
out _);
out var migratorData);

if (migrationsToRevert.Count + migrationsToApply.Count == 0)
if (migratorData.RevertedMigrations.Count + migratorData.AppliedMigrations.Count == 0)
{
return;
}

// If a PostgreSQL extension, enum or range was added, we want Npgsql to reload all types at the ADO.NET level.
var migrations = migrationsToApply.Count > 0 ? migrationsToApply : migrationsToRevert;
var migrations = migratorData.AppliedMigrations.Count > 0 ? migratorData.AppliedMigrations : migratorData.RevertedMigrations;
var reloadTypes = migrations
.SelectMany(m => m.UpOperations)
.OfType<AlterDatabaseOperation>()
Expand All @@ -96,9 +97,7 @@ public override void Migrate(string? targetMigration = null)
/// 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.
/// </summary>
public override async Task MigrateAsync(
string? targetMigration = null,
CancellationToken cancellationToken = default)
public override async Task MigrateAsync(string? targetMigration, CancellationToken cancellationToken = default)
{
var appliedMigrations = await _historyRepository.GetAppliedMigrationsAsync(cancellationToken).ConfigureAwait(false);

Expand All @@ -107,17 +106,15 @@ public override async Task MigrateAsync(
PopulateMigrations(
appliedMigrations.Select(t => t.MigrationId),
targetMigration,
out var migrationsToApply,
out var migrationsToRevert,
out _);
out var migratorData);

if (migrationsToRevert.Count + migrationsToApply.Count == 0)
if (migratorData.RevertedMigrations.Count + migratorData.AppliedMigrations.Count == 0)
{
return;
}

// If a PostgreSQL extension, enum or range was added, we want Npgsql to reload all types at the ADO.NET level.
var migrations = migrationsToApply.Count > 0 ? migrationsToApply : migrationsToRevert;
var migrations = migratorData.AppliedMigrations.Count > 0 ? migratorData.AppliedMigrations : migratorData.RevertedMigrations;
var reloadTypes = migrations
.SelectMany(m => m.UpOperations)
.OfType<AlterDatabaseOperation>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class NpgsqlParameterBasedSqlProcessor : RelationalParameterBasedSqlProce
/// </summary>
public NpgsqlParameterBasedSqlProcessor(
RelationalParameterBasedSqlProcessorDependencies dependencies,
bool useRelationalNulls)
: base(dependencies, useRelationalNulls)
RelationalParameterBasedSqlProcessorParameters parameters)
: base(dependencies, parameters)
{
}

Expand Down Expand Up @@ -48,7 +48,7 @@ protected override Expression ProcessSqlNullability(
Check.NotNull(selectExpression, nameof(selectExpression));
Check.NotNull(parametersValues, nameof(parametersValues));

return new NpgsqlSqlNullabilityProcessor(Dependencies, UseRelationalNulls).Process(
return new NpgsqlSqlNullabilityProcessor(Dependencies, Parameters).Process(
selectExpression, parametersValues, out canCache);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ public NpgsqlParameterBasedSqlProcessorFactory(
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// Creates a new <see cref="RelationalParameterBasedSqlProcessor" />.
/// </summary>
public virtual RelationalParameterBasedSqlProcessor Create(bool useRelationalNulls)
=> new NpgsqlParameterBasedSqlProcessor(_dependencies, useRelationalNulls);
/// <param name="parameters">Parameters for <see cref="RelationalParameterBasedSqlProcessor" />.</param>
/// <returns>A relational parameter based sql processor.</returns>
public RelationalParameterBasedSqlProcessor Create(RelationalParameterBasedSqlProcessorParameters parameters)
=> new NpgsqlParameterBasedSqlProcessor(_dependencies, parameters);
}
5 changes: 5 additions & 0 deletions src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,11 @@ protected override Expression VisitValues(ValuesExpression valuesExpression)
/// </summary>
protected override void GenerateValues(ValuesExpression valuesExpression)
{
if (valuesExpression.RowValues is null)
{
throw new UnreachableException();
}

if (valuesExpression.RowValues.Count == 0)
{
throw new InvalidOperationException(RelationalStrings.EmptyCollectionNotSupportedAsInlineQueryRoot);
Expand Down
15 changes: 8 additions & 7 deletions src/EFCore.PG/Query/Internal/NpgsqlSqlNullabilityProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ public class NpgsqlSqlNullabilityProcessor : SqlNullabilityProcessor
private readonly ISqlExpressionFactory _sqlExpressionFactory;

/// <summary>
/// Creates a new instance of the <see cref="NpgsqlSqlNullabilityProcessor" /> class.
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// </summary>
/// <param name="dependencies">Parameter object containing dependencies for this class.</param>
/// <param name="useRelationalNulls">A bool value indicating whether relational null semantics are in use.</param>
public NpgsqlSqlNullabilityProcessor(
RelationalParameterBasedSqlProcessorDependencies dependencies,
bool useRelationalNulls)
: base(dependencies, useRelationalNulls)
RelationalParameterBasedSqlProcessorParameters parameters)
: base(dependencies, parameters)
{
_sqlExpressionFactory = dependencies.SqlExpressionFactory;
}
Expand Down Expand Up @@ -101,7 +102,7 @@ SqlExpression VisitRowValueComparison(
// visit that (that adds the compensation). We then chain all such expressions together with AND.
var valueBinaryExpression = Visit(
_sqlExpressionFactory.MakeBinary(
operatorType, visitedLeftValue, visitedRightValue, typeMapping: null, existingExpr: sqlBinaryExpression)!,
operatorType, visitedLeftValue, visitedRightValue, typeMapping: null, existingExpression: sqlBinaryExpression)!,
allowOptimizedExpansion,
out _);

Expand Down Expand Up @@ -144,7 +145,7 @@ visitedRightValues is null
? rightRowValue
: new PgRowValueExpression(visitedRightValues, leftRowValue.Type, leftRowValue.TypeMapping),
typeMapping: null,
existingExpr: sqlBinaryExpression)!;
existingExpression: sqlBinaryExpression)!;
}

Check.DebugAssert(visitedLeftValues is not null, "visitedLeftValues is not null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<!-- Workaround for unsecure dependency on EF.Specification.Tests -->
<PackageReference Include="System.Formats.Asn1" />
<PackageReference Include="System.Text.Json" />

<!-- Needed to override xunit dependencies from EFCore projects on versions which aren't available on nuget.org -->
<PackageReference Include="xunit.assert" />
Expand Down
4 changes: 2 additions & 2 deletions test/EFCore.PG.FunctionalTests/ExecutionStrategyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void Test_commit_failure(bool realFailure, Action<TestNpgsqlRetryingExec
}
else
{
Assert.Empty(Fixture.TestSqlLoggerFactory.Log.Where(l => l.Id == CoreEventId.ExecutionStrategyRetrying));
Assert.DoesNotContain(Fixture.TestSqlLoggerFactory.Log, l => l.Id == CoreEventId.ExecutionStrategyRetrying);
}

Assert.Equal(realFailure ? 3 : 2, connection.OpenCount);
Expand Down Expand Up @@ -213,7 +213,7 @@ private async Task Test_commit_failure_async(
}
else
{
Assert.Empty(Fixture.TestSqlLoggerFactory.Log.Where(l => l.Id == CoreEventId.ExecutionStrategyRetrying));
Assert.DoesNotContain(Fixture.TestSqlLoggerFactory.Log, l => l.Id == CoreEventId.ExecutionStrategyRetrying);
}

Assert.Equal(realFailure ? 3 : 2, connection.OpenCount);
Expand Down
Loading

0 comments on commit c150540

Please sign in to comment.