PgSqlEntityProviderConfig.Instance.DatabaseScript.Schema.EnsureSchemaBehaviour ignored after version 7.20.* and 7.21.*

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
jamir.araujo
Posts: 16
Joined: Wed 13 Mar 2019 17:25

PgSqlEntityProviderConfig.Instance.DatabaseScript.Schema.EnsureSchemaBehaviour ignored after version 7.20.* and 7.21.*

Post by jamir.araujo » Mon 11 Oct 2021 20:12

Hello! I've notice that from the version v7.20.1782 and after, the package Devart.Data.PostgreSql.EF Core is no longer respecting the config PgSqlEntityProviderConfig.Instance.DatabaseScript.Schema.EnsureSchemaBehaviour.

In some application of my company, we have the need to isolate the tenants by database schema. To enable that, we generate the DbContext migrations without a schema, then, in runtime, we set the ModelBuilder default schema and use a custom IMigrationsAssembly implementantion that sets ModelBuilder default schema for all migration operations.

But after updating beyond v7.19.1759, the schemas are not been created, and I'm receiving the flowing exception when I run the migrations -> Devart.Data.PostgreSql.PgSqlException (0x80004005): schema "c1de5f15-a4c2-484b-8b5e-1c8bf73d1d1e" does not exist at character 14

I tried different values of the config PgSqlEntityProviderConfig.Instance.DatabaseScript.Schema.EnsureSchemaBehaviour with no success.

Shalex
Site Admin
Posts: 9384
Joined: Thu 14 Aug 2008 12:44

Re: PgSqlEntityProviderConfig.Instance.DatabaseScript.Schema.EnsureSchemaBehaviour ignored after version 7.20.* and 7.21

Post by Shalex » Wed 13 Oct 2021 13:39

1. PgSqlEntityProviderConfig.Instance.DatabaseScript.Schema.EnsureSchemaBehaviour controls the behavior of the setting migrationBuilder.EnsureSchema(name: "schema_name_here") only from migration code.

2. As we understood, you use modelBuilder.HasDefaultSchema("schema_name_here"). At the same time, a schema is specified neither in the connection string (Initial Schema) nor in the class mapping nor in the generated migration code. Please download the test project, it includes modelBuilder.HasDefaultSchema("forum48430") but the script produced by script-migration ignores it with both v7.19.1759 and v7.21.1985. Could you modify the test project so that we can reproduce the issue when v7.19.1759 uses the specified schema but v7.21.1985 doesn't? Provide us the modified project via our contact form.

jamir.araujo
Posts: 16
Joined: Wed 13 Mar 2019 17:25

Re: PgSqlEntityProviderConfig.Instance.DatabaseScript.Schema.EnsureSchemaBehaviour ignored after version 7.20.* and 7.21

Post by jamir.araujo » Thu 14 Oct 2021 14:16

I have the modified the project to work with with v7.19.1759. I had to remove the migration that came with it, though. The migration code that came with it had a call to a Navigation method that was not available on EFCore 3.*.

You can run the Script-Migration command and see the script, than when you update to v7.21.1985, and EFCore accordingly, generated the script again and see the change.

I believe the issue has something to do with the migration history table. When using v7.19.1759, the generated script has code to create the migration history table, on v7.21.1985 it doesn't.

About the submission on the contact form. How should I reference this post there?

Shalex
Site Admin
Posts: 9384
Joined: Thu 14 Aug 2008 12:44

Re: PgSqlEntityProviderConfig.Instance.DatabaseScript.Schema.EnsureSchemaBehaviour ignored after version 7.20.* and 7.21

Post by Shalex » Sat 16 Oct 2021 14:15

jamir.araujo wrote: Thu 14 Oct 2021 14:16 About the submission on the contact form. How should I reference this post there?
Just specify the link in the Detailed Info field. Please notify us in this thread after submitting the test project via contact form.

jamir.araujo
Posts: 16
Joined: Wed 13 Mar 2019 17:25

Re: PgSqlEntityProviderConfig.Instance.DatabaseScript.Schema.EnsureSchemaBehaviour ignored after version 7.20.* and 7.21

Post by jamir.araujo » Mon 18 Oct 2021 14:33

I Submited the test project on the contact form.

I was investigating little more and it seems to be a much simpler issue. The v7.21.1985 is just not generating the Create Table command for the migration history table.

for this code:

Code: Select all

class Program
{
    static void Main(string[] args)
    {
        var context = new MyDbContext();

        context.Database.Migrate();
    }
}

public class Record
{
    public int Id { get; set; }
    public string Text { get; set; }
}

public class MyDbContext : DbContext
{
    public DbSet<Record> Records { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);

        optionsBuilder.UsePostgreSql("User Id=postgres;Password=admin;Host=localhost;Database=DevartBug;Persist Security Info=True;License Key=...;");
    }
}
If you run Add-Migration and than Update-Database, you will see an exception on the console. If you run Scritp-Migration, you will see that the generate script does not create the __EFMigrationsHistory table.

Shalex
Site Admin
Posts: 9384
Joined: Thu 14 Aug 2008 12:44

Re: PgSqlEntityProviderConfig.Instance.DatabaseScript.Schema.EnsureSchemaBehaviour ignored after version 7.20.* and 7.21

Post by Shalex » Tue 19 Oct 2021 14:44

jamir.araujo wrote: Mon 18 Oct 2021 14:33 If you run Add-Migration and than Update-Database, you will see an exception on the console. If you run Scritp-Migration, you will see that the generate script does not create the __EFMigrationsHistory table.
Thank you for the additional information. We have reproduced the issue and will notify you when it is fixed.

Post Reply