From 789ea00e7f779e981718c8ef723d38941a0c340b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 4 Aug 2019 15:37:53 +0800 Subject: [PATCH] add migration --- models/migrations/migrations.go | 2 ++ models/migrations/v91.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 models/migrations/v91.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 5326022b41613..6459036e4a61a 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -236,6 +236,8 @@ var migrations = []Migration{ NewMigration("add original author/url migration info to issues, comments, and repo ", addOriginalMigrationInfo), // v90 -> v91 NewMigration("change length of some repository columns", changeSomeColumnsLengthOfRepo), + // v91 -> v92 + NewMigration("add index on owner_id of repository and type, review_id of comment", addIndexOnRepositoryAndComment), } // Migrate database to current version diff --git a/models/migrations/v91.go b/models/migrations/v91.go new file mode 100644 index 0000000000000..fea71b5d3b1d9 --- /dev/null +++ b/models/migrations/v91.go @@ -0,0 +1,26 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package migrations + +import "github.com/go-xorm/xorm" + +func addIndexOnRepositoryAndComment(x *xorm.Engine) error { + type Repository struct { + ID int64 `xorm:"pk autoincr"` + OwnerID int64 `xorm:"index"` + } + + if err := x.Sync2(new(Repository)); err != nil { + return err + } + + type Comment struct { + ID int64 `xorm:"pk autoincr"` + Type int `xorm:"index"` + ReviewID int64 `xorm:"index"` + } + + return x.Sync2(new(Comment)) +}