efcore / EFCore.NamingConventions

Entity Framework Core plugin to apply naming conventions to table and column names (e.g. snake_case)
Apache License 2.0
715 stars 73 forks source link

Postgres 63-character column name limit ignored in edge cases in Snake Case mode #289

Open joshuajung opened 2 weeks ago

joshuajung commented 2 weeks ago

Environment

We are using EF with NamingConventions and Npgsql, all in their latest versions.

PostgreSQL has a 63-character limit for column names that Npgsql announces as a RelationalMaxIdentifierLengthConvention.

Without NamingConventions, column names are abbreviated using a ~, ~1, ~2, ... style.

Issue

When using the Snake Case naming convention, this abbreviation does not work as expected if the original C# property name fits within the limit, but the Snake Case version is longer than 63 characters.

To reproduce

  1. Enable the Snake Case naming convention via optionsBuilder.UseSnakeCaseNamingConvention();
  2. Create an Entity with a property named ProviderCreditorUpdateNotificationsLastSendingByEmailsFailedAt (62 characters long)
  3. Create a migration

Expected result

The respective table column is called provider_creditor_update_notifications_last_sending_by_emails_~ (63 characters, fully supported).

Actual result

The respective table column in the migration is called provider_creditor_update_notifications_last_sending_by_emails_failed_at (71 characters), which Postgres then silently truncates to provider_creditor_update_notifications_last_sending_by_emails_f, resulting in all kinds of issues.

Further thoughts