Use the pg_type table to get valid type sizes for numeric types #61
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.
What did this pull request do?
This change uses the pg_type table to get the real size of numeric column types like
integer
andbigint
so that the automigration logic functions correctly.NOTE: this change may trigger column type changes because the previous logic wasn't detecting column type size at all for some types.
For example: in Gorm v1
int
fields were treated as 32-bit values (integer
in postgresql); however, in v2 they are now 64-bit values (bigint
). Because gorm couldn't extract a type size from the type nameinteger
it did not detect that a schema change was needed. With this change, these fields would be migrated frominteger
tobigint
.User Case Description
I described the issue that we were hitting in this issue in the main gorm repo: go-gorm/gorm#4641
In brief: there are some column types that are currently always triggering an
ALTER COLUMN
during migration because gorm misidentifies the current size of the database column. This PR fixes that issue.