fix: solve issue with schema builder default values comparison#11995
fix: solve issue with schema builder default values comparison#11995gioboa wants to merge 2 commits intotypeorm:masterfrom
Conversation
User descriptionClose #1729 Description of changePull-Request Checklist
PR TypeBug fix Description
Diagram Walkthroughflowchart LR
A["PostgreSQL Default Values"] --> B["Query Runner Loads DB Schema"]
B --> C["Driver Compares Column Defaults"]
C --> D["Strip Type Casting for Comparison"]
D --> E["Determine if Column Changed"]
E --> F["Generate Migration Queries"]
|
| Relevant files | |||||
|---|---|---|---|---|---|
| Bug fix |
| ||||
| Tests |
|
PR Code Suggestions ✨Latest suggestions up to be0755e
Previous suggestionsSuggestions up to commit 486a336
Suggestions up to commit dde101a
✅ Suggestions up to commit 628a4d3
✅ Suggestions up to commit 1b20b27
✅ Suggestions up to commit d543450
✅ Suggestions up to commit a3728f5
✅ Suggestions up to commit bbc9ee3
✅ Suggestions up to commit f24280f
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
commit: |
Code Review by Qodo
1. Casts hide real default changes
|
|
Persistent review updated to latest commit 148b87e |
|
Persistent review updated to latest commit c7961ad |
|
Persistent review updated to latest commit f24280f |
|
Persistent review updated to latest commit bbc9ee3 |
|
Persistent review updated to latest commit a3728f5 |
|
Persistent review updated to latest commit d543450 |
|
Persistent review updated to latest commit 1b20b27 |
|
Persistent review updated to latest commit dde101a |
|
Persistent review updated to latest commit 628a4d3 |
|
Persistent review updated to latest commit dde101a |
|
Persistent review updated to latest commit 486a336 |
| if (columnDefault === tableColumn.default) return true | ||
|
|
||
| if ( | ||
| columnDefault && | ||
| tableColumn.default && | ||
| this.stripTypeCastsOutsideQuotes(columnDefault) === | ||
| this.stripTypeCastsOutsideQuotes(tableColumn.default) | ||
| ) { | ||
| return true | ||
| } | ||
|
|
||
| return false |
There was a problem hiding this comment.
1. Casts hide real default changes 🐞 Bug ✓ Correctness
defaultEqual now falls back to comparing defaults after stripping all ::type casts outside quotes on both sides. This can collapse semantically different defaults (e.g., different datetime function normalizations/types) into the same string and prevent schema builder from detecting a real default change.
Agent Prompt
### Issue description
`defaultEqual` uses `stripTypeCastsOutsideQuotes` as a fallback equality check. Because the stripper removes *all* `::type` casts (outside quotes) across the whole expression, semantically different defaults that rely on casts/type distinctions can be treated as equal, preventing schema diffs/migrations.
### Issue Context
- `normalizeDatetimeFunction` intentionally returns different expressions for `CURRENT_DATE` vs `LOCALTIMESTAMP`, differing primarily by casts/type.
- The fallback equality removes those casts, making them comparable as identical strings.
### Fix Focus Areas
- src/driver/postgres/PostgresDriver.ts[1251-1267]
- src/driver/postgres/PostgresDriver.ts[1794-1826]
- src/driver/postgres/PostgresDriver.ts[1844-1860]
### Suggested direction
- Consider stripping casts only from `tableColumn.default` (database side), and only those casts that Postgres injects around literals / at the end of the expression (e.g., `'<literal>'::type`, or an outermost trailing cast), instead of stripping every cast everywhere.
- Add a regression test that changes a column default between two different datetime defaults (e.g. CURRENT_DATE vs LOCALTIMESTAMP) and ensure a schema diff is produced.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Persistent review updated to latest commit be0755e |
alumni
left a comment
There was a problem hiding this comment.
We should probably do some things similar in CockroachDB.
Probably in the long term we should find a way to reuse code, so we can benefit from the fixes (maybe we put a halt on the dialect task and think about it a bit better).
Close #1729
Description of change
Pull-Request Checklist
masterbranchFixes #00000tests/**.test.ts)docs/docs/**.md)