mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-31 03:18:43 -06:00
Don't rewrite enum columns when not necessary.
This commit is contained in:
@@ -134,6 +134,17 @@ type TypeInfo interface {
|
||||
fmt.Stringer
|
||||
}
|
||||
|
||||
// RequiresRewrite returns whether or now changing a column type from |old| to |new| requires rewriting table rows.
|
||||
func RequiresRewrite(old TypeInfo, new TypeInfo) bool {
|
||||
oldEnum, isOldEnum := old.ToSqlType().(sql.EnumType)
|
||||
newEnum, isNewEnum := new.ToSqlType().(sql.EnumType)
|
||||
if isOldEnum && isNewEnum && oldEnum.IsSubsetOf(newEnum) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// FromSqlType takes in a sql.Type and returns the most relevant TypeInfo.
|
||||
func FromSqlType(sqlType sql.Type) (TypeInfo, error) {
|
||||
if gmsExtendedType, ok := sqlType.(gmstypes.ExtendedType); ok {
|
||||
|
||||
@@ -1682,7 +1682,7 @@ func (t *AlterableDoltTable) isIncompatibleTypeChange(oldColumn *sql.Column, new
|
||||
if !existingCol.TypeInfo.Equals(newCol.TypeInfo) {
|
||||
if types.IsFormat_DOLT(t.Format()) {
|
||||
// This is overly broad, we could narrow this down a bit
|
||||
return true
|
||||
return typeinfo.RequiresRewrite(existingCol.TypeInfo, newCol.TypeInfo)
|
||||
}
|
||||
if existingCol.Kind != newCol.Kind {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user