Page 1 of 1

Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Posted: Wed 13 Nov 2019 17:26
by jamir.araujo
Hey, I'm having to make some customizations on EntityFrameworkCore to allow the generation, and execution of migrations scripts with dynamic schema.

The central idea is that migrations will be created at development time without schema, than some time latter will be executed several times with different schema, that will be set as the default schema for model of the DbContext at runtime.

To allow that, I had to replace the IMigrationsAssembly service with a custom one. My custom implementation just inheret from the default MigrationsAssembly class and override the values of the properties Schema and PrincipalSchema for all MigrationOperations from a given DbContext.

This works for the SqlServer provider, and the Npgsql provider for PostgreSQL. But I'm facing a issue with your EFCore provider.

When I have an entity with a int key, the script generated does not mark the key column as serial type.

What I was able to find, was that the CreateTableOperation has a Columns property that is a list os AddColumnOperation. This type also has a Schema property. When the Schema property of the AddColumnOperation that is resposible for the key column is set or overriden, the Create Table statement in the generated script, will not mark the key column as serial.

This Github repository has this scenario. https://github.com/jamir-araujo/DevartCustomMigration

To reproduce, open the solution, go to the Package Manager Console, select the EntityFramework.Devart.PostgreSql project, and execute the command Script-Migration -from 0 -to CreateDatabase.

This will generate a migration script with the issue described.

Now, go to the ForceSchemaMigrationsAssembly class that is on the EntityFramework.Devart.PostgreSql projetct, uncomment the line if (addColumnOperation.Name != "Id") and execute the previous Script-Migration command again.

This time the migration script is correct.

Re: Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Posted: Fri 15 Nov 2019 15:52
by Shalex
Thank you for your report. We will investigate the issue and notify you about the result.

Re: Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Posted: Tue 30 Jun 2020 21:13
by jamir.araujo
Any news about this essue?

Re: Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Posted: Tue 14 Jul 2020 18:36
by Shalex
The investigation is in progress. An approximate timeframe for the fix is one month.

Re: Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Posted: Wed 23 Dec 2020 21:19
by jamir.araujo
Any news about this essue?

Re: Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Posted: Fri 25 Dec 2020 12:49
by Shalex
Sorry for the delay in providing the fix. We are going to solve the issue in January 2021.

Re: Devart.Data.PostgreSql.Entity.EFCore not marking int keys as serial when generating migration script

Posted: Fri 15 Jan 2021 14:50
by Shalex
The new metadata to describe autoincremental columns via annotations in EF Core Code-First Migrations are implemented in dotConnect for PostgreSQL v7.20.1812: viewtopic.php?f=3&t=44357.

The previous code generation by EF Code-First Migrations for autoincremental column:

Code: Select all

            migrationBuilder.CreateTable(
                // [...]
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false),
                    // [...]
                },
The current code generation:

Code: Select all

            migrationBuilder.CreateTable(
                // [...]
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("Devart.Data.PostgreSql:Autoincrement", true),
                    // [...]
                },