feat: render local artist images with no foreign key

This commit is contained in:
sentriz
2022-02-09 17:55:19 +00:00
committed by Senan Kelly
parent a0b9934d08
commit a74b5a261c
10 changed files with 160 additions and 49 deletions

View File

@@ -37,6 +37,8 @@ func (db *DB) Migrate(ctx MigrationContext) error {
construct(ctx, "202102191448", migratePodcastAutoDownload),
construct(ctx, "202110041330", migrateAlbumCreatedAt),
construct(ctx, "202111021951", migrateAlbumRootDir),
construct(ctx, "202201042236", migrateArtistGuessedFolder),
construct(ctx, "202202092013", migrateArtistCover),
}
return gormigrate.
@@ -306,3 +308,28 @@ func migrateAlbumRootDir(tx *gorm.DB, ctx MigrationContext) error {
}
return nil
}
func migrateArtistGuessedFolder(tx *gorm.DB, ctx MigrationContext) error {
return tx.AutoMigrate(Artist{}).Error
}
func migrateArtistCover(tx *gorm.DB, ctx MigrationContext) error {
step := tx.AutoMigrate(
Artist{},
)
if err := step.Error; err != nil {
return fmt.Errorf("step auto migrate: %w", err)
}
if !tx.Dialect().HasColumn("artists", "guessed_folder_id") {
return nil
}
step = tx.Exec(`
ALTER TABLE artists DROP COLUMN guessed_folder_id
`)
if err := step.Error; err != nil {
return fmt.Errorf("step drop column: %w", err)
}
return nil
}

View File

@@ -48,6 +48,7 @@ type Artist struct {
NameUDec string `sql:"default: null"`
Albums []*Album `gorm:"foreignkey:TagArtistID"`
AlbumCount int `sql:"-"`
Cover string `sql:"default: null"`
}
func (a *Artist) SID() *specid.ID {