简体   繁体   中英

How to rename generated table references?

I have two schemas in my database and both share tables with the same names. In order to not have naming conflicts in generated code, I want to prefix all names with the appropriate schema name.

I made it work for class names by overriding getJavaClassName of DefaultGeneratorStrategy however I could not find a fitting override that is responsible for the table references in tables.references.Tables.kt .

I managed to solve my problem by overriding getJavaIdentifier of DefaultGeneratorStrategy the following way:

override fun getJavaIdentifier(definition: Definition): String {
    if (definition is PostgresTableDefinition) {
        return "${definition.schema.name.toUppercaseSnakeCase()}_${super.getJavaIdentifier(definition)}"
    }

    return super.getJavaIdentifier(definition)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM