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

MaxIdentifierLength is not supported #192

Open
gscpw opened this issue Mar 10, 2023 · 4 comments
Open

MaxIdentifierLength is not supported #192

gscpw opened this issue Mar 10, 2023 · 4 comments
Labels
blocked bug Something isn't working
Milestone

Comments

@gscpw
Copy link

gscpw commented Mar 10, 2023

I use MaxIdentifierLength limit to support Oracle:

public class OpenIddictDbContext : DbContext
{
    public OpenIddictDbContext(DbContextOptions options)
        : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // Oracle limit
        modelBuilder.Model.SetMaxIdentifierLength(30);
    }
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 
        => optionsBuilder.UseSnakeCaseNamingConvention();
}

However, it seems setting the snake_case naming convention ignores the max identifier length and instead generates full-length identifiers. If I do not add snake_case naming convention, the identifiers are limited to 30 chars and are protected against conflict by appending ~, ~1, ~2, etc.

@stamahto
Copy link

Hello, any progress? I have the same problem

@roji
Copy link
Member

roji commented Sep 11, 2023

No progress as of now - I'll probably concentrate on the plugin a bit later in the release, before 8.0 is released.

@roji
Copy link
Member

roji commented Jan 3, 2024

This seems to be specifically a problem when the table name is derived from a DbSet property name; otherwise, if there's no DbSet property, the table name is truncated properly (property names are also truncated).

@AndriySvyryd is it safe to assume that this is a conflict/ordering issue between the convention that sets the table name from the DbSet and the naming rewriting convention?

Repro
public class BlogContext : DbContext
{
    // Commenting out the following makes truncation work
    public DbSet<StudentWithAVeryLongNameExceedingTheMaximum> StudentsWithAnotherLongName { get; set; } = null!;

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseNpgsql("Host=localhost;Username=test;Password=test")
            .UseSnakeCaseNamingConvention()
            .LogTo(Console.WriteLine, LogLevel.Information)
            .EnableSensitiveDataLogging();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Model.SetMaxIdentifierLength(10);
        modelBuilder.Entity<StudentWithAVeryLongNameExceedingTheMaximum>();
    }
}

public class StudentWithAVeryLongNameExceedingTheMaximum
{
    public int Id { get; set; }

    public string? PropertyNameThatIsVeryLong1 { get; set; }
    public string? PropertyNameThatIsVeryLong2 { get; set; }
}

@roji roji added this to the Backlog milestone Jan 3, 2024
@roji roji added bug Something isn't working blocked labels Jan 3, 2024
@AndriySvyryd
Copy link

There's definitely a conflict, but I couldn't say where the fix for it should be without investigating the root cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants