diff --git a/migrations.moon b/migrations.moon index 075e033..29d868d 100644 --- a/migrations.moon +++ b/migrations.moon @@ -27,7 +27,7 @@ import Tracks, Tags from require "models" } add_column "tracks", unpack column [3]: => - -- NOTE: bad migration! + -- NOTE: bad migration! (introduces more tags than it should) for track in *Tracks\select "*" tags = "" for field in *{"artist", "mood", "link", "genre"} @@ -37,7 +37,7 @@ import Tracks, Tags from require "models" track.tags = process_tags trim(track.tags or "untagged") .. tags track\update "tags" [4]: => - -- WARNING: removes all tags! + -- NOTE: bad migration! (doesn't save changes to database) for track in *Tracks\select "*" tags = "" for field in *{"artist", "mood", "link", "genre"} @@ -62,5 +62,16 @@ import Tracks, Tags from require "models" tags[name] = 1 for name, count in pairs tags Tags\create { :name, :count } - + [6]: => + -- WARNING: removes all tags! + for track in *Tracks\select "*" + tags = "" + for field in *{"artist", "mood", "link", "genre"} + if track[field] and #track[field] > 0 + tags ..= " #{field}:#{track[field]}" + if #tags > 0 + track.tags = process_tags "untagged" .. tags + else + track.tags = " untagged " + track\update "tags" }