dont run genre migration if there are no genres
This commit is contained in:
@@ -43,6 +43,7 @@ func migrateCreateInitUser() gormigrate.Migration {
|
|||||||
if !gorm.IsRecordNotFoundError(err) {
|
if !gorm.IsRecordNotFoundError(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Create(&User{
|
return tx.Create(&User{
|
||||||
Name: initUsername,
|
Name: initUsername,
|
||||||
Password: initPassword,
|
Password: initPassword,
|
||||||
@@ -60,6 +61,7 @@ func migrateMergePlaylist() gormigrate.Migration {
|
|||||||
if !tx.HasTable("playlist_items") {
|
if !tx.HasTable("playlist_items") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Exec(`
|
return tx.Exec(`
|
||||||
UPDATE playlists
|
UPDATE playlists
|
||||||
SET items=( SELECT group_concat(track_id) FROM (
|
SET items=( SELECT group_concat(track_id) FROM (
|
||||||
@@ -116,18 +118,21 @@ func migrateUpdateTranscodePrefIDX() gormigrate.Migration {
|
|||||||
// index already exists
|
// index already exists
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
step := tx.Exec(`
|
step := tx.Exec(`
|
||||||
ALTER TABLE transcode_preferences RENAME TO transcode_preferences_orig;
|
ALTER TABLE transcode_preferences RENAME TO transcode_preferences_orig;
|
||||||
`)
|
`)
|
||||||
if err := step.Error; err != nil {
|
if err := step.Error; err != nil {
|
||||||
return fmt.Errorf("step rename: %w", err)
|
return fmt.Errorf("step rename: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
step = tx.AutoMigrate(
|
step = tx.AutoMigrate(
|
||||||
TranscodePreference{},
|
TranscodePreference{},
|
||||||
)
|
)
|
||||||
if err := step.Error; err != nil {
|
if err := step.Error; err != nil {
|
||||||
return fmt.Errorf("step create: %w", err)
|
return fmt.Errorf("step create: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
step = tx.Exec(`
|
step = tx.Exec(`
|
||||||
INSERT INTO transcode_preferences (user_id, client, profile)
|
INSERT INTO transcode_preferences (user_id, client, profile)
|
||||||
SELECT user_id, client, profile
|
SELECT user_id, client, profile
|
||||||
@@ -165,6 +170,14 @@ func migrateMultiGenre() gormigrate.Migration {
|
|||||||
TrackGenre{},
|
TrackGenre{},
|
||||||
AlbumGenre{},
|
AlbumGenre{},
|
||||||
)
|
)
|
||||||
|
var genreCount int
|
||||||
|
tx.
|
||||||
|
Model(Genre{}).
|
||||||
|
Count(&genreCount)
|
||||||
|
if genreCount == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := step.Error; err != nil {
|
if err := step.Error; err != nil {
|
||||||
return fmt.Errorf("step auto migrate: %w", err)
|
return fmt.Errorf("step auto migrate: %w", err)
|
||||||
}
|
}
|
||||||
@@ -175,6 +188,7 @@ func migrateMultiGenre() gormigrate.Migration {
|
|||||||
WHERE tag_genre_id IS NOT NULL;
|
WHERE tag_genre_id IS NOT NULL;
|
||||||
UPDATE tracks SET tag_genre_id=NULL;
|
UPDATE tracks SET tag_genre_id=NULL;
|
||||||
`)
|
`)
|
||||||
|
|
||||||
if err := step.Error; err != nil {
|
if err := step.Error; err != nil {
|
||||||
return fmt.Errorf("step migrate track genres: %w", err)
|
return fmt.Errorf("step migrate track genres: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user