🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
feat: rename year to max_year and add min_year to album. #118
Deluan53e8a92fed66
diff --git a/db/migration/20200327193744_add_year_range_to_album.go b/db/migration/20200327193744_add_year_range_to_album.gonew file mode 100644index 000000000..7ec3def33--- /dev/null+++ b/db/migration/20200327193744_add_year_range_to_album.go@@ -0,0 +1,80 @@+package migration++import (+ "database/sql"+ "github.com/pressly/goose"+)++func init() {+ goose.AddMigration(Up20200327193744, Down20200327193744)+}++func Up20200327193744(tx *sql.Tx) error {+ _, err := tx.Exec(`+create table album_dg_tmp+(+ id varchar(255) not null+ primary key,+ name varchar(255) default '' not null,+ artist_id varchar(255) default '' not null,+ cover_art_path varchar(255) default '' not null,+ cover_art_id varchar(255) default '' not null,+ artist varchar(255) default '' not null,+ album_artist varchar(255) default '' not null,+ min_year int default 0 not null,+ max_year integer default 0 not null,+ compilation bool default FALSE not null,+ song_count integer default 0 not null,+ duration real default 0 not null,+ genre varchar(255) default '' not null,+ created_at datetime,+ updated_at datetime,+ full_text varchar(255) default '',+ album_artist_id varchar(255) default ''+);++insert into album_dg_tmp(id, name, artist_id, cover_art_path, cover_art_id, artist, album_artist, max_year, compilation, song_count, duration, genre, created_at, updated_at, full_text, album_artist_id) select id, name, artist_id, cover_art_path, cover_art_id, artist, album_artist, year, compilation, song_count, duration, genre, created_at, updated_at, full_text, album_artist_id from album;++drop table album;++alter table album_dg_tmp rename to album;++create index album_artist+ on album (artist);++create index album_artist_album+ on album (artist);++create index album_artist_album_id+ on album (album_artist_id);++create index album_artist_id+ on album (artist_id);++create index album_full_text+ on album (full_text);++create index album_genre+ on album (genre);++create index album_name+ on album (name);++create index album_min_year+ on album (min_year);++create index album_max_year+ on album (max_year);++`)+ if err != nil {+ return err+ }+ notice(tx, "A full rescan will be performed!")+ return forceFullRescan(tx)+}++func Down20200327193744(tx *sql.Tx) error {+ // This code is executed when the migration is rolled back.+ return nil+}diff --git a/engine/browser.go b/engine/browser.goindex 3bd3d56c5..e85946834 100644--- a/engine/browser.go+++ b/engine/browser.go@@ -161,7 +161,7 @@ func (b *browser) buildAlbumDir(al *model.Album, tracks model.MediaFiles) *DirecSongCount: al.SongCount,Duration: int(al.Duration),Created: al.CreatedAt,- Year: al.Year,+ Year: al.MaxYear,Genre: al.Genre,CoverArt: al.CoverArtId,PlayCount: int32(al.PlayCount),diff --git a/engine/common.go b/engine/common.goindex b50768a23..955ce856b 100644--- a/engine/common.go+++ b/engine/common.go@@ -65,7 +65,7 @@ func FromAlbum(al *model.Album) Entry {e.IsDir = truee.Parent = al.AlbumArtistIDe.Album = al.Name- e.Year = al.Year+ e.Year = al.MaxYeare.Artist = al.AlbumArtiste.Genre = al.Genree.CoverArt = al.CoverArtIddiff --git a/model/album.go b/model/album.goindex da8732451..320c4df00 100644--- a/model/album.go+++ b/model/album.go@@ -11,7 +11,8 @@ type Album struct {Artist string `json:"artist"`AlbumArtistID string `json:"albumArtistId" orm:"pk;column(album_artist_id)"`AlbumArtist string `json:"albumArtist"`- Year int `json:"year"`+ MaxYear int `json:"maxYear"`+ MinYear int `json:"minYear"`Compilation bool `json:"compilation"`SongCount int `json:"songCount"`Duration float32 `json:"duration"`diff --git a/persistence/album_repository.go b/persistence/album_repository.goindex 385a952ed..7cf4f2691 100644--- a/persistence/album_repository.go+++ b/persistence/album_repository.go@@ -73,7 +73,7 @@ func (r *albumRepository) Get(id string) (*model.Album, error) {}func (r *albumRepository) FindByArtist(artistId string) (model.Albums, error) {- sq := r.selectAlbum().Where(Eq{"album_artist_id": artistId}).OrderBy("year")+ sq := r.selectAlbum().Where(Eq{"album_artist_id": artistId}).OrderBy("max_year")res := model.Albums{}err := r.queryAll(sq, &res)return res, err@@ -103,8 +103,8 @@ func (r *albumRepository) Refresh(ids ...string) error {}var albums []refreshAlbumsel := Select(`album_id as id, album as name, f.artist, f.album_artist, f.artist_id, f.album_artist_id,- f.compilation, f.genre, max(f.year) as year, sum(f.duration) as duration, count(*) as song_count, a.id as current_id,- f.id as cover_art_id, f.path as cover_art_path, f.has_cover_art`).+ f.compilation, f.genre, max(f.year) as max_year, min(f.year) as min_year, sum(f.duration) as duration,+ count(*) as song_count, a.id as current_id, f.id as cover_art_id, f.path as cover_art_path, f.has_cover_art`).From("media_file f").LeftJoin("album a on f.album_id = a.id").Where(Eq{"f.album_id": ids}).GroupBy("album_id").OrderBy("f.id")diff --git a/persistence/persistence_suite_test.go b/persistence/persistence_suite_test.goindex ebad4a106..65fd2cda0 100644--- a/persistence/persistence_suite_test.go+++ b/persistence/persistence_suite_test.go@@ -40,8 +40,8 @@ var ()var (- albumSgtPeppers = model.Album{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", AlbumArtistID: "3", Genre: "Rock", CoverArtId: "1", CoverArtPath: P("/beatles/1/sgt/a day.mp3"), SongCount: 1, Year: 1967, FullText: "sgt peppers the beatles"}- albumAbbeyRoad = model.Album{ID: "2", Name: "Abbey Road", Artist: "The Beatles", AlbumArtistID: "3", Genre: "Rock", CoverArtId: "2", CoverArtPath: P("/beatles/1/come together.mp3"), SongCount: 1, Year: 1969, FullText: "abbey road the beatles"}+ albumSgtPeppers = model.Album{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", AlbumArtistID: "3", Genre: "Rock", CoverArtId: "1", CoverArtPath: P("/beatles/1/sgt/a day.mp3"), SongCount: 1, MaxYear: 1967, FullText: "sgt peppers the beatles"}+ albumAbbeyRoad = model.Album{ID: "2", Name: "Abbey Road", Artist: "The Beatles", AlbumArtistID: "3", Genre: "Rock", CoverArtId: "2", CoverArtPath: P("/beatles/1/come together.mp3"), SongCount: 1, MaxYear: 1969, FullText: "abbey road the beatles"}albumRadioactivity = model.Album{ID: "3", Name: "Radioactivity", Artist: "Kraftwerk", AlbumArtistID: "2", Genre: "Electronic", CoverArtId: "3", CoverArtPath: P("/kraft/radio/radio.mp3"), SongCount: 2, FullText: "radioactivity kraftwerk"}testAlbums = model.Albums{albumSgtPeppers,diff --git a/ui/src/album/AlbumDetails.js b/ui/src/album/AlbumDetails.jsindex deac9f093..719f4155d 100644--- a/ui/src/album/AlbumDetails.js+++ b/ui/src/album/AlbumDetails.js@@ -11,8 +11,8 @@ const AlbumDetails = ({ classes, record }) => {if (record.genre) {genreDateLine.push(record.genre)}- if (record.year) {- genreDateLine.push(record.year)+ if (record.maxYear) {+ genreDateLine.push(record.maxYear)}return genreDateLine.join(' · ')}diff --git a/ui/src/album/AlbumList.js b/ui/src/album/AlbumList.jsindex b357619b8..0d1c96ecc 100644--- a/ui/src/album/AlbumList.js+++ b/ui/src/album/AlbumList.js@@ -31,7 +31,7 @@ const AlbumFilter = (props) => (<AutocompleteInput emptyText="-- None --" /></ReferenceInput><NullableBooleanInput source="compilation" />- <NumberInput source="year" />+ <NumberInput source="max_year" /></Filter>)@@ -68,7 +68,7 @@ const AlbumList = (props) => {render={(r) => (r.albumArtist ? r.albumArtist : r.artist)}/>{isDesktop && <NumberField source="songCount" />}- <TextField source="year" />+ <TextField source="maxYear" />{isDesktop && <DurationField source="duration" />}</Datagrid></List>diff --git a/ui/src/artist/ArtistList.js b/ui/src/artist/ArtistList.jsindex f33a08cb1..3236eef8f 100644--- a/ui/src/artist/ArtistList.js+++ b/ui/src/artist/ArtistList.js@@ -19,7 +19,7 @@ const artistRowClick = (id, basePath, record) => {const filter = { artist_id: id }return `/album?filter=${JSON.stringify(filter- )}&order=ASC&sort=year&displayedFilters={"compilation":true}`+ )}&order=ASC&sort=maxYear&displayedFilters={"compilation":true}`}const ArtistList = (props) => (diff --git a/ui/src/song/SongList.js b/ui/src/song/SongList.jsindex f200d2441..9fdc39098 100644--- a/ui/src/song/SongList.js+++ b/ui/src/song/SongList.js@@ -83,7 +83,7 @@ const SongList = (props) => {{isDesktop && <TextField source="album" />}<TextField source="artist" />{isDesktop && <NumberField source="trackNumber" />}- {isDesktop && <TextField source="year" />}+ {isDesktop && <TextField source="maxYear" />}<DurationField source="duration" /></Datagrid>)}