From c5556526b04fc5cac1362c33b126d615dcb1c36f Mon Sep 17 00:00:00 2001 From: Tangent Date: Fri, 14 Jun 2019 17:55:55 -0700 Subject: [PATCH] added tags (ref #4) --- migrations.moon | 18 +++++++++++++++++- models/Tags.moon | 10 ++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 models/Tags.moon diff --git a/migrations.moon b/migrations.moon index 6b69971..075e033 100644 --- a/migrations.moon +++ b/migrations.moon @@ -1,7 +1,7 @@ import create_table, rename_column, add_column, types from require "lapis.db.schema" import trim from require "lapis.util" import process_tags from require "helpers" -import Tracks from require "models" +import Tracks, Tags from require "models" { [1]: => @@ -47,4 +47,20 @@ import Tracks from require "models" track.tags = process_tags "untagged" .. tags else track.tags = " untagged " + [5]: => + create_table "tags", { + { "id", types.serial primary_key: true } + { "name", types.text unique: true } + { "count", types.integer default: -1 } + } + tags = {} + for track in *Tracks\select "*" + for name in track.tags\gmatch "%S+" + if tags[name] + tags[name] += 1 + else + tags[name] = 1 + for name, count in pairs tags + Tags\create { :name, :count } + } diff --git a/models/Tags.moon b/models/Tags.moon new file mode 100644 index 0000000..048518c --- /dev/null +++ b/models/Tags.moon @@ -0,0 +1,10 @@ +import Model, enum from require "lapis.db.model" + +class Tags extends Model + -- @kinds: enum { + -- other: 1 + -- artist: 2 + -- mood: 3 + -- link: 4 + -- genre: 5 + -- }