For jOOQ's code generator on a payments service whose CI runners share no database, which schema source would you make the truth, and why?
answer
- one input: the migrations
- real engine versus simulation
- what the runners can host
- a deprecation narrows the field
basics
~20 sMake the migrations the only truth and generate from a throwaway database of the production engine with them applied; DDLDatabase is a fallback for portable DDL when runners cannot host one. Avoid the deprecated LiquibaseDatabase.
solid answer
~40 sI decide on fidelity first: the generated types should come from the same engine and the same migrations production runs. A throwaway database container on the runner, migrated by the same Flyway or Liquibase step production uses and read through the vendor `Database` class, gives that, at the cost of Docker on every runner and a slower build. `DDLDatabase` removes the infrastructure but replays the scripts on in-memory H2 through jOOQ's parser, so vendor DDL needs `[jooq ignore start]` fences and generated types can differ from what production reports; I accept it for small, portable schemas. `LiquibaseDatabase` is deprecated since jOOQ 3.21.0, so I would not adopt it for new work. Whichever wins, there is exactly one source, the same locally and in CI, and never a developer's hand-altered database.
go deeper
Recall that the generator needs a schema to read and that the migrations, not a hand-edited database, should define it.
Explain the candidates: a real database built from the migrations, DDLDatabase on in-memory H2, and the deprecated LiquibaseDatabase.
Spot the drift each choice risks: simulated types, fenced statements missing from the code, or a live database that no longer matches the migrations.
Own the trade-off between fidelity and build infrastructure, write the choice down with the trigger that would reverse it, and enforce one source everywhere.
## The decision being made jOOQ's code generator needs a **schema source**: something it can read tables, columns, keys and types from. On a team whose CI runners have no shared database, the lead has to name one source as the truth for generated code, for every developer and every pipeline. The choice decides how faithful the generated types are, what infrastructure every build needs, and how future upgrades will go. There is no single right answer; there is a defensible one for a given team. For a payments service the stakes are concrete: a JSON payload column and a status enum column (mapped with forced types), money columns whose precision matters, and a schema that changes through reviewed migrations. ## The candidates **A. A throwaway database of the production engine.** The build starts a disposable database container, applies the migrations with the same tool production uses, and points a vendor source such as `org.jooq.meta.postgres.PostgresDatabase` at it. - Fidelity: what production would report, because it is the same engine running the same scripts. - Cost: Docker (or an equivalent) on every runner and laptop, plus start-up time on each generation. **B. `DDLDatabase` over the migration scripts.** jOOQ parses the scripts, translates them to H2 and runs them on in-memory H2, then reverse-engineers that. - Fidelity: limited by jOOQ's parser and by what H2 can express; vendor statements need `[jooq ignore start]` and `[jooq ignore stop]` fences, and every fenced statement is invisible to the generator. - Cost: no infrastructure, fast, deterministic. **C. `LiquibaseDatabase` over a changelog.** Liquibase applies the changelog to in-memory H2. - Status: deprecated since jOOQ 3.21.0 (#19353) after Liquibase 5.x's license change, and it logs a deprecation warning on every run. **D. A shared or personal live database.** Rejected outright: its schema is whatever someone last did to it, not what the migrations define, and CI here has none to share. ## Comparing them | Criterion | A: real engine | B: DDLDatabase | C: LiquibaseDatabase | |---|---|---|---| | Matches production types | yes | mostly, for portable DDL | mostly | | Infrastructure per build | container runtime | none | none | | Handles vendor DDL | yes | only by fencing it out | limited by H2 | | Future in 3.21 | supported | supported | deprecated | ## How I would decide 1. **List the vendor features the schema uses.** Native enum types, vendor JSON types, extensions, generated columns and procedural code all push towards A, because B can only fence them out. 2. **Check what the runners can host.** If containers are available, A's cost is minutes of build time, not a platform project. 3. **Measure the build-time budget.** A start-up on every generation may matter for a large monorepo; caching the generation task limits it. 4. **Rule out deprecated paths.** A source deprecated in the current release is a migration you will be forced into later, so C is out for new work. 5. **Write the decision down** with its trigger for revisiting, for example "the schema adopts a vendor type that DDLDatabase cannot express". For a payments schema that uses a vendor JSON type and is expected to grow, I would choose A, and keep B as the documented fallback for a runner that cannot host containers. ## Rules that make any choice hold - **One source of truth**: the migrations. The generator reads either a database built only from them or the scripts themselves, never a database someone altered by hand. - **Same configuration locally and in CI**, so a developer and the pipeline generate identical code. - **Fail loudly**: set `onUnused` to `FAIL` (its default is `LOG`) so an unused forced type breaks the build, and review every ignore fence, so drift between schema and code surfaces early. - **One jOOQ version** for generator, extensions and runtime. ## What a strong answer shows A strong answer does not stop at naming a source. It names the cost the team pays, states the condition under which the decision flips, and refuses the options whose truth is not the migrations.
- Under what conditions would you accept jOOQ's DDLDatabase over a real database for codegen?When the schema sticks to portable DDL, such as tables, keys, indexes and standard types, the runners cannot run containers, and the build-time budget is tight. I would want every ignore fence reviewed like code, because each fenced statement is invisible to the generator, and a written trigger to move to a real database once the schema adopts a vendor type.
- A team on Liquibase wants to keep generating jOOQ code through LiquibaseDatabase; what do you tell them?It still runs on 3.21, but it is deprecated since 3.21.0 after Liquibase 5.x's license change, and every run logs a deprecation warning. Building more on it means a forced migration later. Move now to applying the changelog to a throwaway database of the production engine and reading that with the vendor source, which also replaces H2 simulation with the real engine.
- Point codegen at the shared staging database; it is always up to date.
- DDLDatabase output always equals the production engine's, since it runs your scripts.
- LiquibaseDatabase is a safe long-term choice for any Liquibase project.
- Each developer can generate from their own local database.
- The schema source only affects build speed, never the generated types.
Assumes jOOQ 3.21: LiquibaseDatabase is deprecated since 3.21.0, which removes it from the options for new work.