diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-12 17:36:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-12 17:36:21 +0800 |
commit | 5765212c6dbcaeb27779707af3ca57775e535bd9 (patch) | |
tree | d3cf5fcedf21486e3b26731ba93cebd8ee13532b /models/migrations | |
parent | 65baacf2273f74876b3faed93f60641389a20d39 (diff) | |
download | gitea-5765212c6dbcaeb27779707af3ca57775e535bd9.tar.gz gitea-5765212c6dbcaeb27779707af3ca57775e535bd9.zip |
Add owner_name column for table repository for maintaince reason (#9717)
* Add owner_name column for table repository for maintaince reason
* refactor
* Fix tests
* fix test
* fix bug when fork repository
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/migrations')
-rw-r--r-- | models/migrations/migrations.go | 2 | ||||
-rw-r--r-- | models/migrations/v120.go | 20 |
2 files changed, 22 insertions, 0 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index dc5cc48c64..703c168b00 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -294,6 +294,8 @@ var migrations = []Migration{ NewMigration("Add commit id and stale to reviews", addReviewCommitAndStale), // v119 -> v120 NewMigration("Fix migrated repositories' git service type", fixMigratedRepositoryServiceType), + // v120 -> v121 + NewMigration("Add owner_name on table repository", addOwnerNameOnRepository), } // Migrate database to current version diff --git a/models/migrations/v120.go b/models/migrations/v120.go new file mode 100644 index 0000000000..91d5b503f3 --- /dev/null +++ b/models/migrations/v120.go @@ -0,0 +1,20 @@ +// Copyright 2020 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 ( + "xorm.io/xorm" +) + +func addOwnerNameOnRepository(x *xorm.Engine) error { + type Repository struct { + OwnerName string + } + if err := x.Sync2(new(Repository)); err != nil { + return err + } + _, err := x.Exec("UPDATE repository SET owner_name = (SELECT name FROM `user` WHERE `user`.id = repository.owner_id)") + return err +} |