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: 22
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: 9543
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: 22
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: 9543
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: 22
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: 9543
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.

jamir.araujo
Posts: 22
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 » Wed 29 Dec 2021 14:24

Any update on this issue?

I have to update my applications to net6.0 and update EFCore too. So, I will have to move from v7.19.1759 to v7.22.2014 or v7.23.2042, but this issue is an impediment for me.

Do we have a date for this fix to be released?

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

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

Post by Shalex » Thu 06 Jan 2022 12:50

Please be informed that the task to develop the fix for this bug was assigned a high priority.

However, the development process appeared to be a quite complicated one as it involves multiple modules and requires some time.

As of right now, it is hard to provide any possible time frames.

On the other hand, please rest assured that as soon as we have any update on the process we'll let you know immediately.

We greatly appreciate your kind patience and understanding!

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

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

Post by Shalex » Fri 29 Apr 2022 16:52

The bug with missing the CREATE TABLE statement for __EFMigrationsHistory in EF Core 5 and EF Core 6 Migrations is fixed. We will notify you when a new public build of dotConnect for PostgreSQL is available for download.

If you are interested in the internal build with the fix, please submit your request via our contact form.

DmitryGm
Devart Team
Posts: 152
Joined: Fri 11 Dec 2020 10:27

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

Post by DmitryGm » Wed 10 Aug 2022 08:57

The new release of dotConnect for PostgreSQL 8.0.0 is available.
https://www.devart.com/dotconnect/postg ... nload.html

The bug with missing the CREATE TABLE statement for __EFMigrationsHistory in EF Core 5 and EF Core 6 Migrations is fixed.

Post Reply