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

Improve AbstractNamingStrategy to get access to table schema #5084

Closed
mazyvan opened this issue Jan 8, 2024 · 3 comments
Closed

Improve AbstractNamingStrategy to get access to table schema #5084

mazyvan opened this issue Jan 8, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@mazyvan
Copy link

mazyvan commented Jan 8, 2024

Is your feature request related to a problem? Please describe.

Yes, currently there's no way to generate entities for tables with the same name but belonging to different schemas. In Postgres you can create schemas and a table a can exist in 2 different schemas but if you try to generate entities for all the tables in your database you'll get name collisions

Describe the solution you'd like

I noticed there's this naming strategy thing I can use to generate names prefixed by schema that way entities will truly be unique

Describe alternatives you've considered

I considered having a map and running entities generate for different entities and storing the resulting files in different directories. but that's not ideal I think a more scalable solution is to support entities generation names to be made according the schema they belong

Another alternative is to add a new option skipSchemas to the entityGenerator.generate() method to later generate the schema separately but with a class prefix. similar to the skipTables or skipColumns that already exist (not ideal tho)

@mazyvan mazyvan added the enhancement New feature or request label Jan 8, 2024
@B4nan
Copy link
Member

B4nan commented Jan 8, 2024

Not sure I follow here, entity generator already supports multiple schemas and will generate entities from all accessible schemas in postgres. The method that looks for existing tables is using this SQL, which is not limited to a specific schema (it only ignores some system schemas and those you specify in the config.

Here is an example from the tests, the label2_tests table is defined is label_schema schema. The schema is here, and generated entity here. Looks like this is the only test we have, but the code should be already in place. So if you have such an issue, please provide a complete reproduction (in this case a complete sql schema dump is enough probably).

Another alternative is to add a new option skipSchemas to the entityGenerator.generate() method to later generate the schema separately but with a class prefix. similar to the skipTables or skipColumns that already exist (not ideal tho)

In fact, this is already supported, its just not configurable on the entity generator level, its in the schemaGeneartor.ignoreSchema, as that is what drives the schema introspection.

@B4nan
Copy link
Member

B4nan commented Jan 8, 2024

Yes, currently there's no way to generate entities for tables with the same name but belonging to different schemas. In Postgres you can create schemas and a table a can exist in 2 different schemas but if you try to generate entities for all the tables in your database you'll get name collisions

Reading this again, I guess I understand what you mean now. The getClassName method is used to get the generated entity name, but you won't get the current schema name in its parameters, and it will produce the same name for two tables with the same name (regardless of the schema).

@B4nan B4nan closed this as completed in 1e5afb8 Jan 9, 2024
@mazyvan
Copy link
Author

mazyvan commented Jan 9, 2024

@B4nan I was looking at your commit. This is awesome man, highly appreciated 🚀 !
I know there is not much use of postgres schemas out there, but those of us who are in big projects will appreciate it a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants