aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-08-19 05:11:36 +0100
committerGitHub <noreply@github.com>2021-08-19 07:11:36 +0300
commitc9bca8c5e0d31d7c844c8e9c96588d0c7c5e0392 (patch)
tree7d58c3b626ce8d595446cdfeaa85a04debad6b5b /models
parent4aa3cacc4f5a8041d6a1857293f54cc68f550845 (diff)
downloadgitea-c9bca8c5e0d31d7c844c8e9c96588d0c7c5e0392.tar.gz
gitea-c9bca8c5e0d31d7c844c8e9c96588d0c7c5e0392.zip
Recreate Tables should Recreate indexes on MySQL (#16718)
The MySQL indexes are not being renamed at the same time as RENAME table despite the CASCADE. Therefore it is probably better to just recreate the indexes instead. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models')
-rw-r--r--models/migrations/migrations.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 28bf4f6036..13ed70bc4f 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -597,11 +597,26 @@ func recreateTable(sess *xorm.Session, bean interface{}) error {
return err
}
+ if err := sess.Table(tempTableName).DropIndexes(bean); err != nil {
+ log.Error("Unable to drop indexes on temporary table %s. Error: %v", tempTableName, err)
+ return err
+ }
+
// SQLite and MySQL will move all the constraints from the temporary table to the new table
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` RENAME TO `%s`", tempTableName, tableName)); err != nil {
log.Error("Unable to rename %s to %s. Error: %v", tempTableName, tableName, err)
return err
}
+
+ if err := sess.Table(tableName).CreateIndexes(bean); err != nil {
+ log.Error("Unable to recreate indexes on table %s. Error: %v", tableName, err)
+ return err
+ }
+
+ if err := sess.Table(tableName).CreateUniques(bean); err != nil {
+ log.Error("Unable to recreate uniques on table %s. Error: %v", tableName, err)
+ return err
+ }
case setting.Database.UsePostgreSQL:
var originalSequences []string
type sequenceData struct {