Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,15 @@ protected override void Generate(AlterColumnOperation operation, IModel? model,
.Append("TYPE ")
.Append(type);

if (newCollation != oldCollation)
if (newCollation is not null)
{
builder.Append(" COLLATE ").Append(DelimitIdentifier(newCollation ?? "default"));
builder.Append(" COLLATE ").Append(DelimitIdentifier(newCollation));
}
else if (type == oldType)
{
// If the type is the same, make it more explicit that we're just resetting the collation to the default
// (this isn't really required)
builder.Append(" COLLATE ").Append(DelimitIdentifier("default"));
}

builder.AppendLine(";");
Expand Down
20 changes: 18 additions & 2 deletions test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,25 @@ await Test(

public override async Task Alter_column_change_type()
{
await base.Alter_column_change_type();
await Test(
builder => builder.Entity("People").Property<int>("Id"),
builder => builder.Entity("People").Property<string>("SomeColumn")
.HasColumnType("varchar")
.UseCollation(NonDefaultCollation),
builder => builder.Entity("People").Property<string>("SomeColumn")
.HasColumnType("text")
.UseCollation(NonDefaultCollation),
model =>
{
var table = Assert.Single(model.Tables);
var column = Assert.Single(table.Columns, c => c.Name == "SomeColumn");
Assert.Equal(NonDefaultCollation, column.Collation);
});

AssertSql("""ALTER TABLE "People" ALTER COLUMN "SomeColumn" TYPE bigint;""");
AssertSql(
"""
ALTER TABLE "People" ALTER COLUMN "SomeColumn" TYPE text COLLATE "POSIX";
""");
}

public override async Task Alter_column_make_required()
Expand Down