From 5ec435cf9935eeb9fa84f0aa9c96e30f365d7a66 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 10 Oct 2019 15:01:16 +0900 Subject: [PATCH] Fixed episode deletion --- arn/EpisodeAPI.go | 2 +- .../delete-broken-episodes.go | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 patches/delete-broken-episodes/delete-broken-episodes.go 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) +}