I have some entities like so:
```C#
[Table("sensor", Schema = "asset")]
public class Sensor {
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("id")]
public Guid Id { get; set; }
}
If I change the table name to anything (i.e. sensor to sensor_test) and run:
dotnet ef migration add <change table>
I get the following scaffold code:
```C#
migrationBuilder.RenameTable(
name: "sensor",
schema: "asset",
newName: "sensor_test",
newSchema: "asset");
Since I didn't make changes to the schema I believe newSchema should be null per documentation (https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.migrations.migrationbuilder.renametable?view=efcore-2.1).
The reason why I noticed this is because I use PostgreSQL and the generated SQL code is missing a semi-colon which is probably an issues with Npgsql.EntityFrameworkCore.PostgreSQL.
The generated SQL code is:
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '') THEN
ALTER TABLE asset."sensor" RENAME TO sensor_test;
ALTER TABLE asset.sensor SET SCHEMA asset
END IF;
END $$;
EF Core version: 2.2.0-preview2-35157
Npgsql.EntityFrameworkCore.PostgreSQL: 2.1.2
Operating system: Windows 10
IDE: Visual Studio 2017 Version 15.8.9
See discussion in https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/700, this may need to be closed.
The missing semi-colon is an Npgsql-only issue.
However, the fact that newSchema is included in the generated RenameTable() migration does seem like an EF Core issue as mentioned by @SamHuo213 (and @austindrenski in https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/700). It seems like there are two possibilities:
The current functionality is correct; the docs should be updated. @bricelam to provide more details.
PR #11549 fixed an issue where we couldn't tell the difference between these two scenarios:
Now, we always specify newSchema in the C#.
Providers, however, can/should be updated to not generate the ALTER TABLE..SET SCHEMA statement if the schema hasn't changed.
Most helpful comment
PR #11549 fixed an issue where we couldn't tell the difference between these two scenarios:
Now, we always specify
newSchemain the C#.Providers, however, can/should be updated to not generate the ALTER TABLE..SET SCHEMA statement if the schema hasn't changed.