feat: support track level year tags (#661)

* [ PR Year @ Track-level ] This resolves issue #549

* Update db/migrations.go

Co-authored-by: Senan Kelly <senan@senan.xyz>

* [ PR #661 ] Fixes proposed by Sentriz (file indentation, simpler call to functions)

* [ PR #661 ] Fix File indentation for construct_by_folder

* [ PR #661 ] Set known tracks year field to their parent (album) year value ; until next deep scan.

* [ PR #661 ] Fix database field names in sql query

* Update db/migrations.go

Co-authored-by: Senan Kelly <senan@senan.xyz>

* Update db/migrations.go

Co-authored-by: Senan Kelly <senan@senan.xyz>

---------

Co-authored-by: Senan Kelly <senan@senan.xyz>
This commit is contained in:
Kynn | Cherryblue
2026-04-26 03:00:49 +02:00
committed by yaemiku
co-authored by Senan Kelly
parent d42ce531c6
commit e4a07750e4
5 changed files with 24 additions and 2 deletions

No files matched your search

+1
View File
@@ -224,6 +224,7 @@ type Track struct {
TagDiscNumber int `sql:"default: null"`
TagBrainzID string `sql:"default: null"`
TagLyrics string `sql:"default: null"`
TagYear int `sql:"default: null"`
ReplayGainTrackGain float32
ReplayGainTrackPeak float32
+20
View File
@@ -83,6 +83,7 @@ func (db *DB) Migrate(ctx MigrationContext) error {
construct(ctx, "202509301448", migrateAddTrackEmbeddedCover),
construct(ctx, "202512021147", migrateAlbumAddIndexOnCreatedAt),
construct(ctx, "202601201000", migrateAddAlbumDiscTitles),
construct(ctx, "202602061800", migrateAddTrackYear),
}
return gormigrate.
@@ -879,3 +880,22 @@ func migrateAlbumAddIndexOnCreatedAt(tx *gorm.DB, _ MigrationContext) error {
func migrateAddAlbumDiscTitles(tx *gorm.DB, _ MigrationContext) error {
return tx.AutoMigrate(AlbumDiscTitle{}).Error
}
func migrateAddTrackYear(tx *gorm.DB, _ MigrationContext) error {
step := tx.AutoMigrate(Track{})
if err := step.Error; err != nil {
return fmt.Errorf("step auto migrate: %w", err)
}
step = tx.Exec(`
UPDATE tracks
SET tag_year=(SELECT tag_year
FROM albums
WHERE tracks.album_id = albums.id)
`)
if err := step.Error; err != nil {
return fmt.Errorf("step set default track year based on album's : %w", err)
}
return nil
}