2019-04-18 05:08:09 +00:00
|
|
|
import create_table, rename_column, add_column, types from require "lapis.db.schema"
|
2019-06-13 16:11:04 +00:00
|
|
|
import trim from require "lapis.util"
|
|
|
|
import process_tags from require "helpers"
|
2019-06-15 00:55:55 +00:00
|
|
|
import Tracks, Tags from require "models"
|
2019-04-18 04:05:33 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
[1]: =>
|
|
|
|
create_table "tracks", {
|
|
|
|
{ "id", types.serial primary_key: true }
|
|
|
|
{ "artist", types.text null: true }
|
|
|
|
{ "name", types.text null: true }
|
|
|
|
{ "url", types.text null: true }
|
|
|
|
{ "status", types.integer default: 1 }
|
|
|
|
}
|
2019-04-18 05:08:09 +00:00
|
|
|
[2]: =>
|
|
|
|
rename_column "tracks", "name", "title"
|
|
|
|
rename_column "tracks", "url", "link"
|
|
|
|
for column in *{
|
|
|
|
{ "art_url", types.text null: true }
|
|
|
|
{ "file_url", types.text null: true }
|
|
|
|
{ "file_size", types.integer null: true }
|
|
|
|
{ "album", types.text null: true }
|
|
|
|
{ "genre", types.text null: true }
|
|
|
|
{ "tags", types.text default: " untagged " }
|
|
|
|
{ "quality", types.integer default: 1 }
|
|
|
|
{ "mood", types.text null: true }
|
|
|
|
}
|
|
|
|
add_column "tracks", unpack column
|
2019-06-13 16:11:04 +00:00
|
|
|
[3]: =>
|
2019-06-28 02:28:15 +00:00
|
|
|
return true -- formerly a bad migration
|
2019-06-15 00:47:18 +00:00
|
|
|
[4]: =>
|
2019-06-28 02:28:15 +00:00
|
|
|
return true -- formerly a bad migration
|
2019-06-15 00:55:55 +00:00
|
|
|
[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 }
|
2019-06-28 02:26:16 +00:00
|
|
|
[6]: =>
|
2019-06-28 02:33:10 +00:00
|
|
|
return true -- formerly a bad migration
|
|
|
|
[7]: =>
|
2019-06-28 02:26:16 +00:00
|
|
|
-- WARNING: removes all tags!
|
|
|
|
for track in *Tracks\select "*"
|
|
|
|
tags = ""
|
|
|
|
for field in *{"artist", "mood", "link", "genre"}
|
|
|
|
if track[field] and #track[field] > 0
|
2019-06-28 02:33:10 +00:00
|
|
|
tags ..= " #{field}:#{track[field]\gsub "%s+", "_"}"
|
2019-06-28 02:26:16 +00:00
|
|
|
if #tags > 0
|
|
|
|
track.tags = process_tags "untagged" .. tags
|
|
|
|
else
|
|
|
|
track.tags = " untagged "
|
|
|
|
track\update "tags"
|
2019-04-18 04:05:33 +00:00
|
|
|
}
|