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

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

Open
joshuajung opened this issue Aug 28, 2024 · 0 comments

Comments

@joshuajung
Copy link

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

  • If the C# property name is already longer than 63 characters, the abbreviation in ~ style works as expected. The issue only occurs if the property name is shorter than 63 or exactly 63 characters long, but the Snake Case version is longer than the limit.
  • What seems to happen here is that when deciding if the column name fits into the 63 characters limit, the C# property name (without underscores) is used. However, the Snake Case underscores push the column name over the limit.
  • I'm not totally sure if this is an issue for this repository? Apologies if it isn't!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant