Skip to content

Commit 7f6e261

Browse files
committed
Add doctor check to set IsArchived false if it is null (partial backport go-gitea#11853)
Partial backport of go-gitea#11853 Add doctor check to set IsArchived false if it is null. (Migration change unfortunately not possible to be backported.) Fix go-gitea#11824 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 6b1e5f7 commit 7f6e261

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

cmd/doctor.go

+16
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,22 @@ func runDoctorCheckDBConsistency(ctx *cli.Context) ([]string, error) {
574574
}
575575
}
576576

577+
count, err = models.CountNullArchivedRepository()
578+
if err != nil {
579+
return nil, err
580+
}
581+
if count > 0 {
582+
if ctx.Bool("fix") {
583+
updatedCount, err := models.FixNullArchivedRepository()
584+
if err != nil {
585+
return nil, err
586+
}
587+
results = append(results, fmt.Sprintf("%d repositories with null is_archived updated", updatedCount))
588+
} else {
589+
results = append(results, fmt.Sprintf("%d repositories with null is_archived", count))
590+
}
591+
}
592+
577593
//ToDo: function to recalc all counters
578594

579595
return results, nil

models/consistency.go

+12
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,15 @@ func DeleteOrphanedObjects(subject, refobject, joinCond string) error {
283283
Delete("`" + subject + "`")
284284
return err
285285
}
286+
287+
// CountNullArchivedRepository counts the number of repositories with is_archived is null
288+
func CountNullArchivedRepository() (int64, error) {
289+
return x.Where(builder.IsNull{"is_archived"}).Count(new(Repository))
290+
}
291+
292+
// FixNullArchivedRepository sets is_archived to false where it is null
293+
func FixNullArchivedRepository() (int64, error) {
294+
return x.Where(builder.IsNull{"is_archived"}).Cols("is_archived").Update(&Repository{
295+
IsArchived: false,
296+
})
297+
}

0 commit comments

Comments
 (0)