From 9ef148abeb1036e0d0b9899e71c95ecd20701dc4 Mon Sep 17 00:00:00 2001 From: John Olheiser <42128690+jolheiser@users.noreply.github.com> Date: Wed, 11 Dec 2019 22:38:58 -0600 Subject: [PATCH] Fix migration releases (#9319) (#9326) (#9328) * Only sync tags after all batches (#9319) Signed-off-by: jolheiser * Add SyncTags to uploader interface (#9326) * Add sync tags to interface Signed-off-by: jolheiser * Fix revive Signed-off-by: jolheiser --- modules/migrations/base/uploader.go | 1 + modules/migrations/gitea.go | 9 +++++---- modules/migrations/migrate.go | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/migrations/base/uploader.go b/modules/migrations/base/uploader.go index ae1be84b8..257c7a290 100644 --- a/modules/migrations/base/uploader.go +++ b/modules/migrations/base/uploader.go @@ -12,6 +12,7 @@ type Uploader interface { CreateTopics(topic ...string) error CreateMilestones(milestones ...*Milestone) error CreateReleases(releases ...*Release) error + SyncTags() error CreateLabels(labels ...*Label) error CreateIssues(issues ...*Issue) error CreateComments(comments ...*Comment) error diff --git a/modules/migrations/gitea.go b/modules/migrations/gitea.go index 81a6116a2..18f4da758 100644 --- a/modules/migrations/gitea.go +++ b/modules/migrations/gitea.go @@ -288,11 +288,12 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { rels = append(rels, &rel) } - if err := models.InsertReleases(rels...); err != nil { - return err - } - // sync tags to releases in database + return models.InsertReleases(rels...) +} + +// SyncTags syncs releases with tags in the database +func (g *GiteaLocalUploader) SyncTags() error { return models.SyncReleasesWithTags(g.repo, g.gitRepo) } diff --git a/modules/migrations/migrate.go b/modules/migrations/migrate.go index 7a5071e12..e2a2c8b7e 100644 --- a/modules/migrations/migrate.go +++ b/modules/migrations/migrate.go @@ -165,6 +165,11 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts } releases = releases[relBatchSize:] } + + // Once all releases (if any) are inserted, sync any remaining non-release tags + if err := uploader.SyncTags(); err != nil { + return err + } } var commentBatchSize = uploader.MaxBatchInsertSize("comment")