diff options
author | Lauris BH <lauris@nix.lv> | 2017-09-20 08:26:49 +0300 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-09-20 13:26:49 +0800 |
commit | 7a0297819d3aececb8b633de5a2995c40b7bfcae (patch) | |
tree | 7aed967ad21f95df2b16359ec1551662d653a1fd /models/migrations | |
parent | 8b6236d67b21f2a3291207ef77d103a3ce7476ba (diff) | |
download | gitea-7a0297819d3aececb8b633de5a2995c40b7bfcae.tar.gz gitea-7a0297819d3aececb8b633de5a2995c40b7bfcae.zip |
Sync releases table with tags on push and for mirrors (#2459)
* Sync releases table with tags on push and for mirrors
* Code style fixes
* Fix api to return only releases
* Optimize release creation and update
Minimize posibility of race conditions
* Fix release lower tag name updating
* handle tag reference update by addionally comparing commit id
Diffstat (limited to 'models/migrations')
-rw-r--r-- | models/migrations/migrations.go | 2 | ||||
-rw-r--r-- | models/migrations/v42.go | 57 |
2 files changed, 59 insertions, 0 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index c36f6fabb7..d302b2c075 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -132,6 +132,8 @@ var migrations = []Migration{ NewMigration("migrate protected branch struct", migrateProtectedBranchStruct), // v41 -> v42 NewMigration("add default value to user prohibit_login", addDefaultValueToUserProhibitLogin), + // v42 -> v43 + NewMigration("add tags to releases and sync existing repositories", releaseAddColumnIsTagAndSyncTags), } // Migrate database to current version diff --git a/models/migrations/v42.go b/models/migrations/v42.go new file mode 100644 index 0000000000..3547ef1f9e --- /dev/null +++ b/models/migrations/v42.go @@ -0,0 +1,57 @@ +// Copyright 2017 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 ( + "fmt" + + "code.gitea.io/git" + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/log" + + "github.com/go-xorm/xorm" +) + +// ReleaseV39 describes the added field for Release +type ReleaseV39 struct { + IsTag bool `xorm:"NOT NULL DEFAULT false"` +} + +// TableName will be invoked by XORM to customrize the table name +func (*ReleaseV39) TableName() string { + return "release" +} + +func releaseAddColumnIsTagAndSyncTags(x *xorm.Engine) error { + if err := x.Sync2(new(ReleaseV39)); err != nil { + return fmt.Errorf("Sync2: %v", err) + } + + // For the sake of SQLite3, we can't use x.Iterate here. + offset := 0 + pageSize := 20 + for { + repos := make([]*models.Repository, 0, pageSize) + if err := x.Table("repository").Asc("id").Limit(pageSize, offset).Find(&repos); err != nil { + return fmt.Errorf("select repos [offset: %d]: %v", offset, err) + } + for _, repo := range repos { + gitRepo, err := git.OpenRepository(repo.RepoPath()) + if err != nil { + log.Warn("OpenRepository: %v", err) + continue + } + + if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil { + log.Warn("SyncReleasesWithTags: %v", err) + } + } + if len(repos) < pageSize { + break + } + offset += pageSize + } + return nil +} |