From decbc06992fb150a9ab08a2e080998c7d24cb04a Mon Sep 17 00:00:00 2001 From: Tangent Date: Thu, 27 Jun 2019 19:26:16 -0700 Subject: [PATCH] replaced broken migration (#4) with correct version --- migrations.moon | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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" }