This repository has been archived on 2024-09-20. You can view files and clone it, but cannot push or open issues or pull requests.
musicapp/migrations.moon
2019-06-13 09:11:04 -07:00

39 lines
1.3 KiB
Plaintext

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"
{
[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 }
}
[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
[3]: =>
for track in *Tracks\select "*"
tags = ""
for field in *{"artist", "mood", "link", "genre"}
if track[field]
tags ..= " #{field}:#{track[field]}"
if #tags > 0
track.tags = process_tags trim(track.tags or "untagged") .. tags
track\update "tags"
}