diff --git a/arn/EpisodeAPI.go b/arn/EpisodeAPI.go index 9068efad..14927e79 100644 --- a/arn/EpisodeAPI.go +++ b/arn/EpisodeAPI.go @@ -49,6 +49,6 @@ func (episode *Episode) Save() { // Delete deletes the episode list from the database. func (episode *Episode) Delete() error { - DB.Delete("Episode", episode.AnimeID) + DB.Delete("Episode", episode.ID) return nil } diff --git a/patches/delete-broken-episodes/delete-broken-episodes.go b/patches/delete-broken-episodes/delete-broken-episodes.go new file mode 100644 index 00000000..b9062cd1 --- /dev/null +++ b/patches/delete-broken-episodes/delete-broken-episodes.go @@ -0,0 +1,25 @@ +package main + +import ( + "github.com/akyoto/color" + "github.com/animenotifier/notify.moe/arn" +) + +func main() { + color.Yellow("Fixing non-existing anime relations") + defer arn.Node.Close() + + count := 0 + + for episode := range arn.StreamEpisodes() { + anime := episode.Anime() + + if anime == nil { + color.Yellow(episode.AnimeID) + episode.Delete() + count++ + } + } + + color.Green("Finished deleting %d episodes.", count) +}