@@ -74,6 +74,24 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
74
74
}
75
75
}
76
76
77
+ // find releases without existing repository
78
+ count , err = models .CountOrphanedObjects ("release" , "repository" , "release.repo_id=repository.id" )
79
+ if err != nil {
80
+ logger .Critical ("Error: %v whilst counting orphaned objects" , err )
81
+ return err
82
+ }
83
+ if count > 0 {
84
+ if autofix {
85
+ if err = models .DeleteOrphanedObjects ("release" , "repository" , "release.repo_id=repository.id" ); err != nil {
86
+ logger .Critical ("Error: %v whilst deleting orphaned objects" , err )
87
+ return err
88
+ }
89
+ logger .Info ("%d releases without existing repository deleted" , count )
90
+ } else {
91
+ logger .Warn ("%d releases without existing repository" , count )
92
+ }
93
+ }
94
+
77
95
// find pulls without existing issues
78
96
count , err = models .CountOrphanedObjects ("pull_request" , "issue" , "pull_request.issue_id=issue.id" )
79
97
if err != nil {
@@ -110,6 +128,24 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
110
128
}
111
129
}
112
130
131
+ // find attachments without existing issues or releases
132
+ count , err = models .CountOrphanedAttachments ()
133
+ if err != nil {
134
+ logger .Critical ("Error: %v whilst counting orphaned objects" , err )
135
+ return err
136
+ }
137
+ if count > 0 {
138
+ if autofix {
139
+ if err = models .DeleteOrphanedAttachments (); err != nil {
140
+ logger .Critical ("Error: %v whilst deleting orphaned objects" , err )
141
+ return err
142
+ }
143
+ logger .Info ("%d attachments without existing issue or release deleted" , count )
144
+ } else {
145
+ logger .Warn ("%d attachments without existing issue or release" , count )
146
+ }
147
+ }
148
+
113
149
// find null archived repositories
114
150
count , err = models .CountNullArchivedRepository ()
115
151
if err != nil {
0 commit comments