In a project I'm working on we model our database in JPA and then generate
the JOOQ model by programmatically setting up an EntityManager that
initializes the database in H2 and then pass the data source to the
JooqGenerator.
Before running the generator we have various code that fixes small issues
like this, it is very easy using jooqs meta feature:
private void fixPrimaryKeyNames(DSLContext jooq) {
Meta meta = jooq.meta().filterSchemas(s -> s.getName().equals("public"));
meta.getTables().forEach(t -> {
String newName = "pk_" + t.getName();
jooq
.alterTable(t)
.renameConstraint(t.getPrimaryKey().constraint())
.to(newName)
.execute();
});
}
Best regards Jens
On Thursday, 16 September 2021 at 19:53:43 UTC+2 [email protected] wrote:
> You're probably using H2 or some implementation that uses H2 behind the
> scenes, like DDLDatabase or JPADatabase? You could implement your own
> generator strategy:
>
> - Programmatic
> https://www.jooq.org/doc/latest/manual/code-generation/codegen-generatorstrategy/
> - Configurative
> https://www.jooq.org/doc/latest/manual/code-generation/codegen-matcherstrategy/
>
> Or use your actual target database instead for code generation.
> Thanks,
> Lukas
>
> On Thu, Sep 16, 2021 at 6:28 PM 'Gang Luo' via jOOQ User Group <
> [email protected]> wrote:
>
>> Hi folks,
>>
>> One of the file auto-generated by JOOQ is "Indexes.java". Inside it there
>> are primary keys defined like "PRIMARY_KEY_302". That "302" in the name
>> seems a bit random to me. I am wondering where does it come from. Of course
>> to say it is random is incorrect, as I rerun the code gen multiple times it
>> alway produce the same variable names.
>>
>> The reason I ask is because I am generating two set of code from two
>> different DB schema, A and B. Both schema has exactly the same tables and
>> specs/schema, so I expect the code generated from them, specifically for
>> that "Indexes.java", will be the same. The reality is, they are 99% the
>> same. For that 1% difference they are actually "similar" but just not the
>> same. Following are the example of 3 variables generated from the schema A
>> and B that don't match exactly.
>>
>> PRIMARY_KEY_EE -- PRIMARY_KEY_E
>>
>> PRIMARY_KEY_3 -- PRIMARY_KEY_30
>>
>> PRIMARY_KEY_30 -- PRIMARY_KEY_302
>>
>> I am wondering why is that and how can I have both generate the exactly
>> same variables in "Indexes.java".
>>
>> Thanks.
>>
>> -Gang
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jOOQ User Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jooq-user/4ae90136-0831-402e-add7-970c6e8228c9n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/jooq-user/4ae90136-0831-402e-add7-970c6e8228c9n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jooq-user/78f3a712-1506-4598-9cf3-4de16c7654een%40googlegroups.com.