diff options
author | Gusted <williamzijl7@hotmail.com> | 2021-11-14 08:11:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-14 10:11:49 +0200 |
commit | d2163df6a0d6b9663a65438c1d960ea4ab5c2df0 (patch) | |
tree | 821ab5acde9a8f382db637b83f0b3ae1c1f3c6f5 /models | |
parent | 8eddb755086f84c8c1168447391ac04a3a6b7702 (diff) | |
download | gitea-d2163df6a0d6b9663a65438c1d960ea4ab5c2df0.tar.gz gitea-d2163df6a0d6b9663a65438c1d960ea4ab5c2df0.zip |
Fix offBy1 errors (#17606)
* Fix offBy1 errors
- Partially resolves #17596
- Resolve errors from go-critic `offBy1: Index() can return -1; maybe
you wanted to do Index()+1`.
* Match golang spec
* Remove comments
* Update migrations.go
* Apply suggestions from code review
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models')
-rw-r--r-- | models/migrations/migrations.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 2686dfb3cf..c0d8f111d3 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -7,6 +7,7 @@ package migrations import ( "context" + "errors" "fmt" "os" "reflect" @@ -791,8 +792,14 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin } tableSQL := string(res[0]["sql"]) + // Get the string offset for column definitions: `CREATE TABLE ( column-definitions... )` + columnDefinitionsIndex := strings.Index(tableSQL, "(") + if columnDefinitionsIndex < 0 { + return errors.New("couldn't find column definitions") + } + // Separate out the column definitions - tableSQL = tableSQL[strings.Index(tableSQL, "("):] + tableSQL = tableSQL[columnDefinitionsIndex:] // Remove the required columnNames for _, name := range columnNames { |