Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : fail to alter existing boolean column from smallint with default value to boolean in postgres (#180) #181

Merged
merged 12 commits into from May 28, 2023

Conversation

jeffry-luqman
Copy link
Contributor

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

drop existing default value to AlterColumn before change column type.
Without this, it will report error as I described in the issue #180

User Case Description

We used migrator to change column data type

Copy link
Member

@a631807682 a631807682 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it also deleted when automatic transformation is allowed? like smallint -> bigint

@jeffry-luqman
Copy link
Contributor Author

ok, I've fixed it with isUncastableDefaultValue method, If there are other types that have the same problem, we just need to fill in this method.

@a631807682
Copy link
Member

ok, I've fixed it with isUncastableDefaultValue method, If there are other types that have the same problem, we just need to fill in this method.

Can we combine genUsingExpression and isUncastableDefaultValue? They will only work if you need to specify the conversion type.

pseudo code

if specifiedType, isAuto := autoConversion(...); !isAuto {
	// delete if has default value
	// use `USING column::xxx::xxx`
} else {
	// use `USING column::xxx`
}

@jeffry-luqman
Copy link
Contributor Author

i have fixed it using ModifyColumn and DropDefaultValue method, what do you think?

migrator.go Outdated Show resolved Hide resolved
migrator.go Outdated Show resolved Hide resolved
migrator.go Outdated Show resolved Hide resolved
@jeffry-luqman
Copy link
Contributor Author

OK, I've fixed it to modifyColumn

@jinzhu
Copy link
Member

jinzhu commented May 19, 2023

Hi @jeffry-luqman

Can you fix the conflict? thank you.

@jeffry-luqman
Copy link
Contributor Author

Hi @jeffry-luqman

Can you fix the conflict? thank you.

✅ Done

@jinzhu jinzhu merged commit 64c0de1 into go-gorm:master May 28, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants