Skip to content

fix(postgres,cockroachdb): load enum values in declaration order#12404

Merged
pkuczynski merged 3 commits into
masterfrom
fix/postgres-enum-load-order
Apr 23, 2026
Merged

fix(postgres,cockroachdb): load enum values in declaration order#12404
pkuczynski merged 3 commits into
masterfrom
fix/postgres-enum-load-order

Conversation

@pkuczynski
Copy link
Copy Markdown
Member

The Postgres and CockroachDB drivers load enum values from pg_enum without an ORDER BY. Postgres makes no ordering guarantee without one; rows usually come back in enumsortorder (declaration order) but can come back in a different order under parallel scans or after a vacuum, which makes any test or schema comparison that depends on enum order intermittently fail.

Example flaky run: https://github.com/typeorm/typeorm/actions/runs/24801566895/job/72585372203?pr=12401schema builder > column type > enum > enum primary column > should create tables with enum primary column got ['atlassian', 'msGraph'] instead of the declaration order ['msGraph', 'atlassian']. Earlier runs on the same PR had been green — classic missing-order symptom.

Adding ORDER BY "e"."enumsortorder" to the Postgres enum-load query (and ORDER BY inside string_agg on CockroachDB) makes the result deterministic. Other drivers (MySQL, MSSQL, Oracle, SAP HANA, SQLite) are unaffected — they load enum values from a single text blob (column type or check constraint) that already preserves declaration order.

Not a breaking change

Postgres has never guaranteed any ordering without ORDER BY, so no user code should have relied on the previous behavior. In practice most users already got declaration order (that's what PG usually returns). If anything, this fix can prevent spurious synchronize() / migration diffs that would have re-emitted enum DDL when the row order happened to flip.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 22, 2026

Deploying typeorm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7709ee7
Status: ✅  Deploy successful!
Preview URL: https://9ab3fa96.typeorm.pages.dev
Branch Preview URL: https://fix-postgres-enum-load-order.typeorm.pages.dev

View logs

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 22, 2026

commit: 7709ee7

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Apr 22, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Previous review results

Review updated until commit 7709ee7

Results up to commit a4a8ff1


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Qodo Logo

@pkuczynski pkuczynski enabled auto-merge (squash) April 23, 2026 19:21
@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Persistent review updated to latest commit 7709ee7

@pkuczynski pkuczynski merged commit bfa9963 into master Apr 23, 2026
48 checks passed
@pkuczynski pkuczynski deleted the fix/postgres-enum-load-order branch April 23, 2026 19:43
@github-actions github-actions Bot added this to the 1.0 milestone Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants