-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[ENH] Add Naming Convention Option for Database Entity Naming #6337
Comments
Opened enhancement based on discussion. |
The issue here is that this configuration must be set before scaffolding migrations, so its an "everyone gets snake case" or "nobody gets snake case" kind of thing. Once you do elsa-core/src/modules/Elsa.EntityFrameworkCore.MySql/Migrations/Runtime/20250116192733_V3_3.cs Lines 34 to 40 in adea7fa
This is why your attempts at changing the naming convention after the fact had no effect. So i don't think this is really actionable. It might work if you copy this file and change this line
to point at your own assembly and then generate your own set of migrations that include the changed naming conventions. |
I did see how those migrations were coded but I thought there was a way to get in between that process with the naming convention library. Anytime you attach new rules to the model binding of a DbContext I always viewed it as the "new lens" through which the database tables where created/read from. I was expecting it to behave similar to how when you generate identity tables in .NET core or just using the naming conventions on an already existing database. The
But I guess maybe the difference here is that Elsa is doing code-first which is why we can't get in between that process? I was also experimenting with |
No, that distinction isn't meaningful in EFC anymore, there's only code first. (Scaffold-DbContext, which generates a DbContext from a database for example, is not database first, it merely generates a code first model).
Not quite. The way it works is, that when a DbContext is first accessed, EFC builds a Model. That involves discovering all entity types and their data annotations. This then runs all configured (built-in's as well as user defined) model conventions which make changes to the model that was discovered so far, e.g. one convention is to create an index for every navigation property. And then lastly it runs your fluent configuration. At this point, there's a "current model" in memory now that describes how the database should look like that EFC will use to formulate the SQL queries against the database. The optional "code first migrations" feature, once you do the first ever If you now add the naming convention package, that sits at the same stage of the pipeline as "create an index for every navigation property". It will affect the "current model" and if you were inclined to do Changing migrations retroactively is unlikely to work in all but the simplest cases, e.g. let's say you have: |
Elsa's approach is to ship its own DbContext with its own Migrations, all fully self contained. |
I guess I'll just learn to live with the bad naming convention unless it's possible we could just add a migration script to always force postgres and my sql to use snake case while SQL server uses Pascal case? |
Enhancement Request
Enhancement Overview
Database table names and column names default to however they were specified in the migration scripts. On SQL Server this leads to the Quartz tables being all uppercase while Elsa specific tables are all pascal case. On MySQL provider all names are lower case without an underscore making it more difficult to read (i.e.
workflowdefinitions
).Proposed Enhancement
Integrate the EFCore.NamingConventions package and expose the various naming conventions offered by the library as configuration chained options on each Elsa DbContext configuration to modify the table and column names:
The resulting startup would look similar to this:
Use Cases
This gives users flexibility to specify the naming convention that should be used throughout their database to match naming conventions of the platform they are using. MySQL for example is snake case but the default behavior for Elsa's MySQL provider is to just make everything lower case and all run together making it more difficult to read.
Impact of Enhancement
Naming things in the standard the database ensures coding standards and improves the developer experience.
Visuals and Mockups
Here is an initial implementation that seems close. I got Quartz migration history to respect snake casing of the migration history table by extending
CustomHistoryRepository
and replacing it in DI.As for the Elsa configurations, neither
feature.DbContextOptionsBuilder += (_, db) => db.UseSnakeCaseNamingConvention();
orfeature.Services.ConfigureDbContext<ManagementElsaDbContext>(options => options.UseSnakeCaseNamingConvention());
worked. The tables always came out in lowercase and all running together:The text was updated successfully, but these errors were encountered: