summaryrefslogtreecommitdiffstats
path: root/models/migrations
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-06-11 21:18:11 +0100
committerGitHub <noreply@github.com>2020-06-11 16:18:11 -0400
commitb9e281265ee2c510199cd0241ae02bff2bd8ecc1 (patch)
tree68e8d10381432e34992ee9638cc3a262a82e622c /models/migrations
parentb682a2c1b2d5efde24378858453903b5b89d6df8 (diff)
downloadgitea-b9e281265ee2c510199cd0241ae02bff2bd8ecc1.tar.gz
gitea-b9e281265ee2c510199cd0241ae02bff2bd8ecc1.zip
Add migration to set IsArchived false if it is null (#11853)
* Add migration to set IsArchived false if it is null Fix #11824 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add doctor Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models/migrations')
-rw-r--r--models/migrations/migrations.go4
-rw-r--r--models/migrations/v142.go24
2 files changed, 27 insertions, 1 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 432bcffb1b..6cc80249a3 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -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
diff --git a/models/migrations/v142.go b/models/migrations/v142.go
new file mode 100644
index 0000000000..1abdd34961
--- /dev/null
+++ b/models/migrations/v142.go
@@ -0,0 +1,24 @@
+// 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"}).Cols("is_archived").Update(&Repository{
+ IsArchived: false,
+ })
+ if err == nil {
+ log.Debug("Updated %d repositories with is_archived IS NULL", count)
+ }
+ return err
+}