H2 vs PostgreSQL schema mismatch caused silent production enum failure

A batch job in production began failing with an invalid enum error after a migration that had passed cleanly in an H2-based test environment. The root cause was a divergence between test and production migration scripts: H2 stored the status field as a plain VARCHAR, while PostgreSQL enforced it as a native three-value enum — ACTIVE, INACTIVE, and ARCHIVED. A legacy status value, LEGACY_HIDDEN, was silently accepted by H2 but correctly rejected by PostgreSQL's stricter type enforcement. The team switched to Testcontainers running the real PostgreSQL migration script, and the same failure surfaced immediately in a local test run. The incident highlights that in-memory test databases like H2 can miss entire classes of schema-level errors when production uses database-native constraints or enum types.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in