@@ -23,7 +23,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
23
23
// find labels without existing repo or org
24
24
count , err := models .CountOrphanedLabels ()
25
25
if err != nil {
26
- logger .Critical ("Error: %v whilst counting orphaned labels" )
26
+ logger .Critical ("Error: %v whilst counting orphaned labels" , err )
27
27
return err
28
28
}
29
29
if count > 0 {
@@ -41,7 +41,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
41
41
// find IssueLabels without existing label
42
42
count , err = models .CountOrphanedIssueLabels ()
43
43
if err != nil {
44
- logger .Critical ("Error: %v whilst counting orphaned issue_labels" )
44
+ logger .Critical ("Error: %v whilst counting orphaned issue_labels" , err )
45
45
return err
46
46
}
47
47
if count > 0 {
@@ -59,7 +59,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
59
59
// find issues without existing repository
60
60
count , err = models .CountOrphanedIssues ()
61
61
if err != nil {
62
- logger .Critical ("Error: %v whilst counting orphaned issues" )
62
+ logger .Critical ("Error: %v whilst counting orphaned issues" , err )
63
63
return err
64
64
}
65
65
if count > 0 {
@@ -77,7 +77,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
77
77
// find pulls without existing issues
78
78
count , err = models .CountOrphanedObjects ("pull_request" , "issue" , "pull_request.issue_id=issue.id" )
79
79
if err != nil {
80
- logger .Critical ("Error: %v whilst counting orphaned objects" )
80
+ logger .Critical ("Error: %v whilst counting orphaned objects" , err )
81
81
return err
82
82
}
83
83
if count > 0 {
@@ -95,7 +95,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
95
95
// find tracked times without existing issues/pulls
96
96
count , err = models .CountOrphanedObjects ("tracked_time" , "issue" , "tracked_time.issue_id=issue.id" )
97
97
if err != nil {
98
- logger .Critical ("Error: %v whilst counting orphaned objects" )
98
+ logger .Critical ("Error: %v whilst counting orphaned objects" , err )
99
99
return err
100
100
}
101
101
if count > 0 {
@@ -113,7 +113,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
113
113
// find null archived repositories
114
114
count , err = models .CountNullArchivedRepository ()
115
115
if err != nil {
116
- logger .Critical ("Error: %v whilst counting null archived repositories" )
116
+ logger .Critical ("Error: %v whilst counting null archived repositories" , err )
117
117
return err
118
118
}
119
119
if count > 0 {
@@ -132,7 +132,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
132
132
// find label comments with empty labels
133
133
count , err = models .CountCommentTypeLabelWithEmptyLabel ()
134
134
if err != nil {
135
- logger .Critical ("Error: %v whilst counting label comments with empty labels" )
135
+ logger .Critical ("Error: %v whilst counting label comments with empty labels" , err )
136
136
return err
137
137
}
138
138
if count > 0 {
@@ -191,7 +191,8 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
191
191
if setting .Database .UsePostgreSQL {
192
192
count , err = models .CountBadSequences ()
193
193
if err != nil {
194
- logger .Critical ("Error: %v whilst checking sequence values" )
194
+ logger .Critical ("Error: %v whilst checking sequence values" , err )
195
+ return err
195
196
}
196
197
if count > 0 {
197
198
if autofix {
@@ -210,7 +211,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
210
211
// find protected branches without existing repository
211
212
count , err = models .CountOrphanedObjects ("protected_branch" , "repository" , "protected_branch.repo_id=repository.id" )
212
213
if err != nil {
213
- logger .Critical ("Error: %v whilst counting orphaned objects" )
214
+ logger .Critical ("Error: %v whilst counting orphaned objects" , err )
214
215
return err
215
216
}
216
217
if count > 0 {
@@ -225,6 +226,42 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
225
226
}
226
227
}
227
228
229
+ // find deleted branches without existing repository
230
+ count , err = models .CountOrphanedObjects ("deleted_branch" , "repository" , "deleted_branch.repo_id=repository.id" )
231
+ if err != nil {
232
+ logger .Critical ("Error: %v whilst counting orphaned objects" , err )
233
+ return err
234
+ }
235
+ if count > 0 {
236
+ if autofix {
237
+ if err = models .DeleteOrphanedObjects ("deleted_branch" , "repository" , "deleted_branch.repo_id=repository.id" ); err != nil {
238
+ logger .Critical ("Error: %v whilst deleting orphaned objects" , err )
239
+ return err
240
+ }
241
+ logger .Info ("%d deleted branches without existing repository deleted" , count )
242
+ } else {
243
+ logger .Warn ("%d deleted branches without existing repository" , count )
244
+ }
245
+ }
246
+
247
+ // find LFS locks without existing repository
248
+ count , err = models .CountOrphanedObjects ("lfs_lock" , "repository" , "lfs_lock.repo_id=repository.id" )
249
+ if err != nil {
250
+ logger .Critical ("Error: %v whilst counting orphaned objects" , err )
251
+ return err
252
+ }
253
+ if count > 0 {
254
+ if autofix {
255
+ if err = models .DeleteOrphanedObjects ("lfs_lock" , "repository" , "lfs_lock.repo_id=repository.id" ); err != nil {
256
+ logger .Critical ("Error: %v whilst deleting orphaned objects" , err )
257
+ return err
258
+ }
259
+ logger .Info ("%d LFS locks without existing repository deleted" , count )
260
+ } else {
261
+ logger .Warn ("%d LFS locks without existing repository" , count )
262
+ }
263
+ }
264
+
228
265
return nil
229
266
}
230
267
0 commit comments