Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to setup code generation in JOOQ for multiple schemas with the same table structure?

We have a multi-tenant database, where each tenant has their own dedicated schema. The schemas always have identical table structures. What I'm trying to figure out is if there's a way to pass the schema to JOOQ at query time when using code generation to track the schema. Something like:

dslContext.useSchema("schema1").select(A.id).from(A).fetch()

It seems like the schema is always tied to the table object and the only option for mapping at runtime is statically via an input schema and an output schema.

Environmental info: Java/Kotlin, Maven, Spring Boot, Postgres, Flyway

like image 859
jarvis97 Avatar asked Nov 15 '25 09:11

jarvis97


1 Answers

The features you are looking for are:

  • Code generation time schema mapping
  • Runtime schema mapping

See also the FAQ

The simplest solution here is to just turn off the generation of schema information in the code generator:

<outputSchemaToDefault>true</outputSchemaToDefault>

Or at runtime

new Settings().withRenderSchema(false);
like image 97
Lukas Eder Avatar answered Nov 18 '25 19:11

Lukas Eder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!