jooq: jOOQ 3.21.9 on Spring Boot 4.2.0 - codegen from Flyway migrations, typed queries, MULTISET, transactions, Testcontainers, fourteen real transcripts

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7h4ZNF4BDUpJk3Zou
This commit is contained in:
Ankur Mhatre
2026-11-29 02:25:52 +05:30
co-authored by Claude Sonnet 5.5
parent 8d8c28e2e5
commit 3f061c5e5d
57 changed files with 3319 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Regenerate src/main/java/com/ankurm/jooq/generated from the Flyway migrations.
# 1. start a throwaway PostgreSQL 17 2. flyway:migrate 3. jooq-codegen:generate 4. remove the container
# Usage: scripts/codegen.sh [-Dflyway.target=1] (extra args go to Maven)
set -euo pipefail
cd "$(dirname "$0")/.."
NAME=jooq-codegen-pg
docker rm -f "$NAME" >/dev/null 2>&1 || true
docker run -d --name "$NAME" -p 55432:5432 \
-e POSTGRES_DB=bookshop -e POSTGRES_USER=bookshop -e POSTGRES_PASSWORD=bookshop \
postgres:17-alpine >/dev/null
trap 'docker rm -f "$NAME" >/dev/null 2>&1 || true' EXIT
for i in $(seq 1 60); do
docker exec "$NAME" pg_isready -U bookshop -d bookshop >/dev/null 2>&1 && break
sleep 1
done
sleep 2
rm -rf src/main/java/com/ankurm/jooq/generated
mvn -B -q -Pcodegen "$@" flyway:migrate jooq-codegen:generate
echo "generated files:"
find src/main/java/com/ankurm/jooq/generated -name '*.java' | sort
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Shows what the compiler says in three situations. Works on a throwaway copy of the module.
# A. wrong Java type in a condition (BOOK.PRICE.eq("12.50"))
# B. a column name typo (BOOK.ISBNN)
# C. the schema changes under existing code (regenerate WITHOUT migration V2: BOOK.ISBN disappears)
set -uo pipefail
HERE="$(cd "$(dirname "$0")/.." && pwd)"
OUT="$HERE/output/10-compile-errors.txt"
WORK="$(mktemp -d)"
filter() { sed -e '/Failed to execute goal/,$d' | grep -v -E 'Picked up|^WARNING|COMPILATION ERROR|^\[ERROR\] *$|^[[:space:]]*$' | sed -e "s#/tmp/[^ ]*/m/##" -e 's/^\[ERROR\] //' -e 's/\x1b\[[0-9;]*m//g'; }
mkdir -p "$WORK/m" && cp -r "$HERE/pom.xml" "$HERE/src" "$HERE/scripts" "$WORK/m/"
cd "$WORK/m"
: > "$OUT"
echo "== A. wrong type: BOOK.PRICE.eq(\"12.50\") ==" >> "$OUT"
cp "$HERE/src/broken/WrongType.java" src/main/java/com/ankurm/jooq/
mvn -B -q compile 2>&1 | filter >> "$OUT"
rm src/main/java/com/ankurm/jooq/WrongType.java
echo >> "$OUT"; echo "== B. typo: BOOK.ISBNN ==" >> "$OUT"
cp "$HERE/src/broken/Typo.java" src/main/java/com/ankurm/jooq/
mvn -B -q compile 2>&1 | filter >> "$OUT"
rm src/main/java/com/ankurm/jooq/Typo.java
echo >> "$OUT"; echo "== C. regenerate from schema version 1 only (no isbn column), compile the unchanged application ==" >> "$OUT"
"$WORK/m/scripts/codegen.sh" -Dflyway.target=1 > /dev/null 2>&1
mvn -B -q compile 2>&1 | filter >> "$OUT"
cd "$HERE"; rm -rf "$WORK"
cat "$OUT"
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Reproduces the Testcontainers + Spring context-cache trap: a per-class @Container is stopped after
# the first test class, but Spring reuses the cached ApplicationContext (and its connection pool) for the next one.
set -uo pipefail
HERE="$(cd "$(dirname "$0")/.." && pwd)"
OUT="$HERE/output/09-container-lifecycle-trap.txt"
WORK="$(mktemp -d)"
mkdir -p "$WORK/m" && cp -r "$HERE/pom.xml" "$HERE/src" "$WORK/m/"
cd "$WORK/m"
python3 - <<'PY'
p='src/test/java/com/ankurm/jooq/PostgresTestBase.java'
s=open(p).read()
s=s.replace('@SpringBootTest\nabstract','@org.testcontainers.junit.jupiter.Testcontainers\n@SpringBootTest\nabstract')
s=s.replace(' @ServiceConnection\n static final PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:17-alpine");\n\n static {\n postgres.start();\n }\n',
' @org.testcontainers.junit.jupiter.Container\n @ServiceConnection\n static PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:17-alpine");\n')
open(p,'w').write(s)
PY
{
echo "per-class @Container, two test classes sharing one cached Spring context (hikari connection-timeout shortened to 2 s)"
mvn -B -q test -DargLine="-Dspring.datasource.hikari.connection-timeout=2000" -Dtest='TransactionTests,QueryTests' 2>&1 \
| grep -E 'Tests run:|TransientDataAccessResourceException|Connection is not available|Failed to validate connection' | sed 's/^[0-9:.]* //' | sed -E 's/PgConnection@[0-9a-f]+/PgConnection@HASH/; s/^[0-9T:.+-]+ +//' | sort | uniq -c | sed 's/^ *//' | cut -c1-260 | head -12
} > "$OUT"
cd "$HERE"; rm -rf "$WORK"
cat "$OUT"
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# What happens when someone adds a migration but forgets to regenerate: run the drift test on a
# throwaway copy that has an extra migration V3.
set -uo pipefail
HERE="$(cd "$(dirname "$0")/.." && pwd)"
OUT="$HERE/output/11-drift-detected.txt"
WORK="$(mktemp -d)"
mkdir -p "$WORK/m" && cp -r "$HERE/pom.xml" "$HERE/src" "$WORK/m/"
cd "$WORK/m"
cat > src/main/resources/db/migration/V3__book_subtitle.sql <<'SQL'
ALTER TABLE book ADD COLUMN subtitle TEXT;
SQL
{
echo "added src/main/resources/db/migration/V3__book_subtitle.sql, did NOT regenerate"
mvn -B -q test -Dtest=CodegenDriftTest 2>&1 | grep -E 'Tests run:|AssertionFailedError|generated code is stale' | head -5 | cut -c1-400
} > "$OUT"
cd "$HERE"; rm -rf "$WORK"
cat "$OUT"
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# What a Flyway 12 + PostgreSQL project does without the separate flyway-database-postgresql module.
set -uo pipefail
HERE="$(cd "$(dirname "$0")/.." && pwd)"
OUT="$HERE/output/14-missing-flyway-database-module.txt"
WORK="$(mktemp -d)"
mkdir -p "$WORK/m" && cp -r "$HERE/pom.xml" "$HERE/src" "$WORK/m/"
cd "$WORK/m"
python3 - <<'PY'
import re
s=open('pom.xml').read()
s=s.replace(''' <dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
''','',1)
open('pom.xml','w').write(s)
PY
{
echo "flyway-database-postgresql removed from the application dependencies"
mvn -B -q test -Dtest=JooqSliceTest 2>&1 | grep -E 'Caused by: org.flywaydb.core.api.FlywayException|Tests run:.*Fail' | sed -E 's/^[0-9T:.+-]+ +(WARN|ERROR|INFO) +[0-9]+ --- \[[^]]*\] \[[^]]*\] //' | awk '!s[$0]++' | cut -c1-300 | head -6
} > "$OUT"
cd "$HERE"; rm -rf "$WORK"
cat "$OUT"
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Regenerates every file in output/. Needs Docker (Testcontainers starts PostgreSQL 17) and JDK 25.
# 01-08, 12 written by the test suite (each test also asserts what it prints)
# 09, 10, 11 written by scripts that break a throwaway copy of the module on purpose
# 00 the code generator run (scripts/codegen.sh)
set -euo pipefail
cd "$(dirname "$0")/.."
mvn -B -q test
scripts/container-trap.sh >/dev/null
scripts/compile-errors.sh >/dev/null
scripts/drift-demo.sh >/dev/null
scripts/startup-warnings.sh >/dev/null
scripts/missing-flyway-module.sh >/dev/null
sums() { find src/main/java/com/ankurm/jooq/generated -name '*.java' | sort | xargs sha256sum | sha256sum | cut -c1-16; }
BEFORE="$(sums)"
{
echo "\$ scripts/codegen.sh"
scripts/codegen.sh 2>&1 | grep -v -E 'Picked up|^WARNING'
echo
echo "checksum of generated sources before: $BEFORE"
echo "checksum of generated sources after: $(sums)"
} > output/00-codegen-run.txt
echo "wrote:"; ls output
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Captures the startup lines a reader will see in the log: the jOOQ banner version and the dialect WARN.
set -uo pipefail
cd "$(dirname "$0")/.."
{
mvn -B -q test -Dtest=JooqSliceTest 2>&1 | grep -E 'Thank you for using jOOQ|Version mismatch|PostgreSQL 17|Successfully applied|Starting JooqSliceTest' \
| sed -E 's/localhost:[0-9]+/localhost:PORT/; s/^[0-9T:.+-]+ +(INFO|WARN) +[0-9]+ --- \[[^]]*\] \[[^]]*\] //; s/ +/ /g; s/PID [0-9]+/PID N/; s/ \(started by [^)]*\)//; s/@+ +//'
} > output/13-startup-log-lines.txt
cat output/13-startup-log-lines.txt