Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,19 @@ public NpgsqlMigrationsAnnotationProvider(MigrationsAnnotationProviderDependenci
/// </summary>
public override IEnumerable<IAnnotation> ForRemove(IRelationalModel model)
=> model.Model.GetAnnotations().Where(NpgsqlAnnotationHelper.IsRelationalModelAnnotation);

/// <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.
/// </summary>
public override IEnumerable<IAnnotation> ForRemove(ITableIndex index)
{
// Model validation ensures that these facets are the same on all mapped indexes
if (index.MappedIndexes.First().IsCreatedConcurrently() is { } isCreatedConcurrently)
{
yield return new Annotation(NpgsqlAnnotationNames.CreatedConcurrently, isCreatedConcurrently);
}
}
}
15 changes: 11 additions & 4 deletions src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,14 +1491,21 @@ protected override void Generate(
Check.NotNull(operation, nameof(operation));
Check.NotNull(builder, nameof(builder));

builder
.Append("DROP INDEX ")
.Append(DelimitIdentifier(operation.Name, operation.Schema));
builder.Append("DROP INDEX ");

var concurrently = operation[NpgsqlAnnotationNames.CreatedConcurrently] as bool? == true;
if (concurrently)
{
builder.Append("CONCURRENTLY ");
}

builder.Append(DelimitIdentifier(operation.Name, operation.Schema));

if (terminate)
{
builder.AppendLine(";");
EndStatement(builder);
// Concurrent indexes cannot be dropped within a transaction
EndStatement(builder, suppressTransaction: concurrently);
}
}

Expand Down
18 changes: 18 additions & 0 deletions test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,24 @@ await Test(
AssertSql("""CREATE INDEX CONCURRENTLY "IX_People_Age" ON "People" ("Age");""");
}

[Fact]
public virtual async Task Drop_index_concurrently()
{
await Test(
builder => builder.Entity(
"People", e =>
{
e.Property<int>("Id");
e.Property<int>("Age");
}),
builder => builder.Entity("People").HasIndex("Age")
.IsCreatedConcurrently(),
_ => { },
asserter: null); // No scaffolding for IsCreatedConcurrently

AssertSql("""DROP INDEX CONCURRENTLY "IX_People_Age";""");
}

[Fact]
public virtual async Task Create_index_with_method()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,43 @@ public override void InsertDataOperation_throws_for_unsupported_column_types()

#pragma warning restore 618

[Fact]
public virtual void DropIndexOperation_concurrently()
{
Generate(
new DropIndexOperation
{
Name = "IX_People_Name",
Table = "People",
Schema = "dbo",
[NpgsqlAnnotationNames.CreatedConcurrently] = true
});

AssertSql(
"""
DROP INDEX CONCURRENTLY dbo."IX_People_Name";

""");
}

[Fact]
public virtual void DropIndexOperation_not_concurrently()
{
Generate(
new DropIndexOperation
{
Name = "IX_People_Name",
Table = "People",
Schema = "dbo"
});

AssertSql(
"""
DROP INDEX dbo."IX_People_Name";

""");
}

protected override string GetGeometryCollectionStoreType()
=> "GEOMETRY(GEOMETRYCOLLECTION)";
}
Loading