go-gorm / postgres

GORM PostgreSQL driver
MIT License
234 stars 123 forks source link

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

Closed jeffry-luqman closed 1 year ago

jeffry-luqman commented 1 year ago

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

jeffry-luqman commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

jeffry-luqman commented 1 year ago

OK, I've fixed it to modifyColumn

jinzhu commented 1 year ago

Hi @jeffry-luqman

Can you fix the conflict? thank you.

jeffry-luqman commented 1 year ago

Hi @jeffry-luqman

Can you fix the conflict? thank you.

✅ Done