mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	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> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		| @@ -1916,3 +1916,70 @@ func UpdateReactionsMigrationsByType(gitServiceType structs.GitServiceType, orig | ||||
| 		}) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func deleteIssuesByRepoID(sess Engine, repoID int64) (attachmentPaths []string, err error) { | ||||
| 	deleteCond := builder.Select("id").From("issue").Where(builder.Eq{"issue.repo_id": repoID}) | ||||
|  | ||||
| 	// Delete comments and attachments | ||||
| 	if _, err = sess.In("issue_id", deleteCond). | ||||
| 		Delete(&Comment{}); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	// Dependencies for issues in this repository | ||||
| 	if _, err = sess.In("issue_id", deleteCond). | ||||
| 		Delete(&IssueDependency{}); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	// Delete dependencies for issues in other repositories | ||||
| 	if _, err = sess.In("dependency_id", deleteCond). | ||||
| 		Delete(&IssueDependency{}); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.In("issue_id", deleteCond). | ||||
| 		Delete(&IssueUser{}); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.In("issue_id", deleteCond). | ||||
| 		Delete(&Reaction{}); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.In("issue_id", deleteCond). | ||||
| 		Delete(&IssueWatch{}); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.In("issue_id", deleteCond). | ||||
| 		Delete(&Stopwatch{}); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.In("issue_id", deleteCond). | ||||
| 		Delete(&TrackedTime{}); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	var attachments []*Attachment | ||||
| 	if err = sess.In("issue_id", deleteCond). | ||||
| 		Find(&attachments); err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	for j := range attachments { | ||||
| 		attachmentPaths = append(attachmentPaths, attachments[j].LocalPath()) | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.In("issue_id", deleteCond). | ||||
| 		Delete(&Attachment{}); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if _, err = sess.Delete(&Issue{RepoID: repoID}); err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	return | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user