feat: add CreatedAt to albums (#159)
This change will make the GetAlbumList views with the "newest" type work as expected.
This commit is contained in:
@@ -82,6 +82,7 @@ func New(path string) (*DB, error) {
|
||||
migratePodcast(),
|
||||
migrateBookmarks(),
|
||||
migratePodcastAutoDownload(),
|
||||
migrateAlbumCreatedAt(),
|
||||
))
|
||||
if err = migr.Migrate(); err != nil {
|
||||
return nil, fmt.Errorf("migrating to latest version: %w", err)
|
||||
|
||||
@@ -262,3 +262,24 @@ func migratePodcastAutoDownload() gormigrate.Migration {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func migrateAlbumCreatedAt() gormigrate.Migration {
|
||||
return gormigrate.Migration{
|
||||
ID: "202110041330",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
step := tx.AutoMigrate(
|
||||
Album{},
|
||||
)
|
||||
if err := step.Error; err != nil {
|
||||
return fmt.Errorf("step auto migrate: %w", err)
|
||||
}
|
||||
step = tx.Exec(`
|
||||
UPDATE albums SET created_at=modified_at;
|
||||
`)
|
||||
if err := step.Error; err != nil {
|
||||
return fmt.Errorf("step migrate album created_at: %w", err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +179,7 @@ type Play struct {
|
||||
|
||||
type Album struct {
|
||||
ID int `gorm:"primary_key"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
ModifiedAt time.Time
|
||||
LeftPath string `gorm:"unique_index:idx_left_path_right_path"`
|
||||
|
||||
Reference in New Issue
Block a user