fix(postgres,cockroachdb): load enum values in declaration order#12404
Merged
Conversation
Deploying typeorm with
|
| 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 |
commit: |
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewPrevious review resultsReview updated until commit 7709ee7 Results up to commit a4a8ff1
Great, no issues found!Qodo reviewed your code and found no material issues that require review |
Cprakhar
approved these changes
Apr 22, 2026
gioboa
approved these changes
Apr 23, 2026
alumni
approved these changes
Apr 23, 2026
|
Persistent review updated to latest commit 7709ee7 |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



The Postgres and CockroachDB drivers load enum values from
pg_enumwithout anORDER BY. Postgres makes no ordering guarantee without one; rows usually come back inenumsortorder(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=12401 —
schema builder > column type > enum > enum primary column > should create tables with enum primary columngot['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 (andORDER BYinsidestring_aggon 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 spurioussynchronize()/ migration diffs that would have re-emitted enum DDL when the row order happened to flip.