Skip to content

Commit

Permalink
Add migration to set IsArchived false if it is null
Browse files Browse the repository at this point in the history
Fix go-gitea#11824

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Jun 11, 2020
1 parent 4a4977a commit 9ac8d0b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ var migrations = []Migration{
NewMigration("prepend refs/heads/ to issue refs", prependRefsHeadsToIssueRefs),
// v140 -> v141
NewMigration("Save detected language file size to database instead of percent", fixLanguageStatsToSaveSize),
// v141 -> 142
// v141 -> v142
NewMigration("Add KeepActivityPrivate to User table", addKeepActivityPrivateUserColumn),
// v142 -> v143
NewMigration("Ensure Repository.IsArchived is not null", setIsArchivedToFalse),
}

// GetCurrentDBVersion returns the current db version
Expand Down
22 changes: 22 additions & 0 deletions models/migrations/v142.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 (
"code.gitea.io/gitea/modules/log"
"xorm.io/builder"
"xorm.io/xorm"
)

func setIsArchivedToFalse(x *xorm.Engine) error {
type Repository struct {
IsArchived bool `xorm:"INDEX"`
}
count, err := x.Where(builder.IsNull{"is_archived"}).SetExpr("is_archived", false).Update(new(Repository))
if err == nil {
log.Debug("Updated %d repositories with is_archived IS NULL", count)
}
return err
}

0 comments on commit 9ac8d0b

Please sign in to comment.