forked from forgejo/forgejo
Fix dropTableColumns sqlite implementation (#7710)
* Fix dropTableColumns sqlite implementation * use droptables and its index dropping support in v78 and v85 * golang-ci fixes * Add migration from gitea 1.3.3 for sqlite which reveals the droptables bug - thus showing this works
This commit is contained in:
parent
7ad67109d7
commit
026696b87a
4 changed files with 24 additions and 98 deletions
|
@ -327,11 +327,25 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
|
|||
return err
|
||||
}
|
||||
tableSQL := string(res[0]["sql"])
|
||||
|
||||
// Separate out the column definitions
|
||||
tableSQL = tableSQL[strings.Index(tableSQL, "("):]
|
||||
|
||||
// Remove the required columnNames
|
||||
for _, name := range columnNames {
|
||||
tableSQL = regexp.MustCompile(regexp.QuoteMeta("`"+name+"`")+"[^`,)]*[,)]").ReplaceAllString(tableSQL, "")
|
||||
tableSQL = regexp.MustCompile(regexp.QuoteMeta("`"+name+"`")+"[^`,)]*?[,)]").ReplaceAllString(tableSQL, "")
|
||||
}
|
||||
|
||||
// Ensure the query is ended properly
|
||||
tableSQL = strings.TrimSpace(tableSQL)
|
||||
if tableSQL[len(tableSQL)-1] != ')' {
|
||||
if tableSQL[len(tableSQL)-1] == ',' {
|
||||
tableSQL = tableSQL[:len(tableSQL)-1]
|
||||
}
|
||||
tableSQL += ")"
|
||||
}
|
||||
|
||||
// Find all the columns in the table
|
||||
columns := regexp.MustCompile("`([^`]*)`").FindAllString(tableSQL, -1)
|
||||
|
||||
tableSQL = fmt.Sprintf("CREATE TABLE `new_%s_new` ", tableName) + tableSQL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue