Add `songCount` column to Artist table

This commit is contained in:
Deluan 2020-05-08 09:50:33 -04:00 committed by Deluan Quintão
parent 1c41582d79
commit 70047fe20e
5 changed files with 34 additions and 4 deletions

View File

@ -0,0 +1,27 @@
package migration
import (
"database/sql"
"github.com/pressly/goose"
)
func init() {
goose.AddMigration(Up20200508093059, Down20200508093059)
}
func Up20200508093059(tx *sql.Tx) error {
_, err := tx.Exec(`
alter table artist
add song_count integer default 0 not null;
`)
if err != nil {
return err
}
notice(tx, "A full rescan will be performed to calculate artists' song counts")
return forceFullRescan(tx)
}
func Down20200508093059(tx *sql.Tx) error {
return nil
}

View File

@ -5,7 +5,8 @@ import "time"
type Artist struct {
ID string `json:"id" orm:"column(id)"`
Name string `json:"name"`
AlbumCount int `json:"albumCount" orm:"column(album_count)"`
AlbumCount int `json:"albumCount"`
SongCount int `json:"songCount"`
FullText string `json:"fullText"`
SortArtistName string `json:"sortArtistName"`
OrderArtistName string `json:"orderArtistName"`

View File

@ -114,8 +114,8 @@ func (r *artistRepository) Refresh(ids ...string) error {
}
var artists []refreshArtist
sel := Select("f.album_artist_id as id", "f.album_artist as name", "count(*) as album_count", "a.id as current_id",
"f.sort_album_artist_name as sort_artist_name",
"f.order_album_artist_name as order_artist_name").
"f.sort_album_artist_name as sort_artist_name", "f.order_album_artist_name as order_artist_name",
"sum(f.song_count) as song_count").
From("album f").
LeftJoin("artist a on f.album_artist_id = a.id").
Where(Eq{"f.album_artist_id": ids}).

View File

@ -38,6 +38,7 @@ const ArtistList = (props) => (
<Datagrid rowClick={artistRowClick}>
<TextField source="name" />
<NumberField source="albumCount" />
<NumberField source="songCount" />
</Datagrid>
</List>
)

View File

@ -49,7 +49,8 @@
"name": "Artist |||| Artists",
"fields": {
"name": "Name",
"albumCount": "Album Count"
"albumCount": "Album Count",
"songCount": "Song Count"
}
},
"user": {