needed to fix issue as described in #10280
* rename check-db to check-db-version
* add check-db-consistency:
* find issues without existing repository
* find pulls without existing issues
* find tracked times without existing issues/pulls
* find labels without repository or org reference
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
returnnil,fmt.Errorf("model version on the database does not match the current Gitea version. Model consistency will not be checked until the database is upgraded")
}
//find labels without existing repo or org
count,err:=models.CountOrphanedLabels()
iferr!=nil{
returnnil,err
}
ifcount>0{
ifctx.Bool("fix"){
iferr=models.DeleteOrphanedLabels();err!=nil{
returnnil,err
}
results=append(results,fmt.Sprintf("%d labels without existing repository/organisation deleted",count))
}else{
results=append(results,fmt.Sprintf("%d labels without existing repository/organisation",count))
}
}
//find issues without existing repository
count,err=models.CountOrphanedIssues()
iferr!=nil{
returnnil,err
}
ifcount>0{
ifctx.Bool("fix"){
iferr=models.DeleteOrphanedIssues();err!=nil{
returnnil,err
}
results=append(results,fmt.Sprintf("%d issues without existing repository deleted",count))
}else{
results=append(results,fmt.Sprintf("%d issues without existing repository",count))