Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapEnum usage not respecting schema boundary #1799

Closed
leonibr opened this issue Apr 13, 2021 · 2 comments
Closed

MapEnum usage not respecting schema boundary #1799

leonibr opened this issue Apr 13, 2021 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@leonibr
Copy link

leonibr commented Apr 13, 2021

Hi, thank you in advance for your time reading this issue!

I noticed that specifying a custom schema name on code first migrations and Mapping enums to Postgres in OnModelCreating it generates a script that ignores the informed schema when applying to columns, therefore it is not respecting the schema boundary!

// in a different assembly
namespace Domain {
    public enum TicketStatus {
        NotInformed,
        Opened,
        Closed,
        ReOpened,
        Terminated
    }
}
// => Domain.dll

//DbContext simplified
public class AppDbContext : DbContext
{

    static AppDbContext()
    {
          NpgsqlConnection.GlobalTypeMapper.MapEnum<Domain.TicketStatus>();
     }
    
    protected override void OnModelCreating(ModelBuilder modelBuilder)
     {
                base.OnModelCreating(modelBuilder);
                modelBuilder.HasDefaultSchema(nameof(MyApp));
                modelBuilder.HasPostgresEnum<Domain.TicketStatus>();
                modelBuilder.ToSnakeCase(); <-- lib to format to snake_case, commenting this line does not affect the output.
                //... 
    
    }
}

It generates something like this:

CREATE TYPE myapp.ticket_status AS ENUM ('not_informed', 'opened', 'closed', 're_opened', 'terminated');

ALTER TABLE myapp.ticket_store ALTER COLUMN status TYPE ticket_status;

I believe the expected behavior should be:

ALTER TABLE myapp.ticket_store ALTER COLUMN status TYPE myapp.ticket_status;

(Partial) Workaround:

I solved the problem by adding the search path key into my connection string:

  "ConnectionStrings": {
    "TheMainAppDb": "Database=database;Server=host;User Id=user;Password=******;Search Path=myapp",
    "OtherDb": "..."
  }

This was working fine until I needed a different enum/type in other schema inside the same database...

Thanks

@roji
Copy link
Member

roji commented Apr 14, 2021

Duplicate of #930

@roji roji marked this as a duplicate of #930 Apr 14, 2021
@roji roji closed this as completed Apr 14, 2021
@roji roji added the duplicate This issue or pull request already exists label Apr 14, 2021
@leonibr
Copy link
Author

leonibr commented Apr 14, 2021

Sorry @roji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants