Skip to content

Commit 474ed8c

Browse files
authored
Minor code tidy up (#2126)
1 parent 65143e6 commit 474ed8c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

internal/sql/catalog/types.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,30 +211,31 @@ func (c *Catalog) alterTypeAddValue(stmt *ast.AlterTypeAddValueStmt) error {
211211
}
212212
}
213213

214+
insertIndex := len(enum.Vals)
214215
if stmt.NewValHasNeighbor {
215-
insertIndex := -1
216+
foundNeighbor := false
216217
for i, val := range enum.Vals {
217218
if val == *stmt.NewValNeighbor {
218219
if stmt.NewValIsAfter {
219220
insertIndex = i + 1
220221
} else {
221222
insertIndex = i
222223
}
224+
foundNeighbor = true
225+
break
223226
}
224227
}
225228

226-
if insertIndex == -1 {
229+
if !foundNeighbor {
227230
return fmt.Errorf("enum %s unable to find existing neighbor value %s for new value %s", enum.Name, *stmt.NewValNeighbor, *stmt.NewValue)
228231
}
232+
}
229233

230-
if insertIndex == len(enum.Vals) {
231-
enum.Vals = append(enum.Vals, *stmt.NewValue)
232-
} else {
233-
enum.Vals = append(enum.Vals[:insertIndex+1], enum.Vals[insertIndex:]...)
234-
enum.Vals[insertIndex] = *stmt.NewValue
235-
}
236-
} else {
234+
if insertIndex == len(enum.Vals) {
237235
enum.Vals = append(enum.Vals, *stmt.NewValue)
236+
} else {
237+
enum.Vals = append(enum.Vals[:insertIndex+1], enum.Vals[insertIndex:]...)
238+
enum.Vals[insertIndex] = *stmt.NewValue
238239
}
239240

240241
return nil

0 commit comments

Comments
 (0)