postgresqlspring-bootjooqflywayjooq-codegen-maven

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


Solution

  • The features you are looking for are:

    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);