feat: Add id column to song table and prep for UUID migration
- Add id serial4 PK to song table (was composite PK) - Update queries to use soundtrack_id + path - Add UUID columns to soundtrack and song (nullable) - Add migration tracking table TODO: Run sqlc generate, then create backfill migration (000008) Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -39,7 +39,13 @@ var gamesChangedTitle map[string]string
|
||||
var gamesChangedContent []string
|
||||
var gamesRemoved []string
|
||||
var catchedErrors []string
|
||||
var brokenSongs []string
|
||||
|
||||
type brokenSong struct {
|
||||
SoundtrackID int32
|
||||
Path string
|
||||
}
|
||||
|
||||
var brokenSongs []brokenSong
|
||||
var pool *ants.Pool
|
||||
var poolSong *ants.Pool
|
||||
|
||||
@@ -262,8 +268,10 @@ func checkBrokenSongsNew() {
|
||||
})
|
||||
}
|
||||
brokenWg.Wait()
|
||||
err = repo.RemoveBrokenSongs(BackendCtx(), brokenSongs)
|
||||
handleError("RemoveBrokenSongs", err, "")
|
||||
for _, bs := range brokenSongs {
|
||||
err = repo.RemoveBrokenSong(BackendCtx(), repository.RemoveBrokenSongParams{SoundtrackID: bs.SoundtrackID, Path: bs.Path})
|
||||
handleError("RemoveBrokenSong", err, "")
|
||||
}
|
||||
}
|
||||
|
||||
func checkBrokenSongNew(song repository.Song) {
|
||||
@@ -271,7 +279,7 @@ func checkBrokenSongNew(song repository.Song) {
|
||||
openFile, err := os.Open(song.Path)
|
||||
if err != nil {
|
||||
//File not found
|
||||
brokenSongs = append(brokenSongs, song.Path)
|
||||
brokenSongs = append(brokenSongs, brokenSong{SoundtrackID: song.SoundtrackID, Path: song.Path})
|
||||
logging.GetLogger().Warn("Broken song found", zap.String("path", song.Path))
|
||||
} else {
|
||||
err = openFile.Close()
|
||||
@@ -493,10 +501,10 @@ func newCheckSong(entry os.DirEntry, gameDir string, id int32) bool {
|
||||
count, err := repo.CheckSongWithHash(BackendCtx(), songHash)
|
||||
handleError("CheckSongWithHash", err, fmt.Sprintf("SoundtrackID: %d | Path: %s | SongName: %s | SongHash: %s\n", id, path, entry.Name(), songHash))
|
||||
if err != nil {
|
||||
count2, err := repo.CheckSong(BackendCtx(), path)
|
||||
count2, err := repo.CheckSong(BackendCtx(), repository.CheckSongParams{SoundtrackID: id, Path: path})
|
||||
handleError("CheckSong", err, fmt.Sprintf("SoundtrackID: %d | Path: %s | SongName: %s | SongHash: %s\n", id, path, entry.Name(), songHash))
|
||||
if count2 > 0 {
|
||||
err = repo.AddHashToSong(BackendCtx(), repository.AddHashToSongParams{Hash: songHash, Path: path})
|
||||
err = repo.AddHashToSong(BackendCtx(), repository.AddHashToSongParams{Hash: songHash, SoundtrackID: id, Path: path})
|
||||
handleError("AddHashToSong", err, fmt.Sprintf("SoundtrackID: %d | Path: %s | SongName: %s | SongHash: %s", id, path, entry.Name(), songHash))
|
||||
count, err = repo.CheckSongWithHash(BackendCtx(), songHash)
|
||||
handleError("CheckSongWithHash 2", err, fmt.Sprintf("SoundtrackID: %d | Path: %s | SongName: %s | SongHash: %s", id, path, entry.Name(), songHash))
|
||||
@@ -508,10 +516,10 @@ func newCheckSong(entry os.DirEntry, gameDir string, id int32) bool {
|
||||
err = repo.UpdateSong(BackendCtx(), repository.UpdateSongParams{SongName: songName, FileName: &fileName, Path: path, Hash: songHash})
|
||||
handleError("UpdateSong", err, fmt.Sprintf("SoundtrackID: %d | Path: %s | SongName: %s | SongHash: %s", id, path, entry.Name(), songHash))
|
||||
} else {
|
||||
count2, err := repo.CheckSong(BackendCtx(), path)
|
||||
count2, err := repo.CheckSong(BackendCtx(), repository.CheckSongParams{SoundtrackID: id, Path: path})
|
||||
handleError("CheckSong", err, fmt.Sprintf("SoundtrackID: %d | Path: %s | SongName: %s | SongHash: %s", id, path, entry.Name(), songHash))
|
||||
if count2 > 0 {
|
||||
err = repo.AddHashToSong(BackendCtx(), repository.AddHashToSongParams{Hash: songHash, Path: path})
|
||||
err = repo.AddHashToSong(BackendCtx(), repository.AddHashToSongParams{Hash: songHash, SoundtrackID: id, Path: path})
|
||||
handleError("AddHashToSong", err, fmt.Sprintf("SoundtrackID: %d | Path: %s | SongName: %s | SongHash: %s", id, path, entry.Name(), songHash))
|
||||
} else {
|
||||
err = repo.AddSong(BackendCtx(), repository.AddSongParams{SoundtrackID: id, SongName: songName, Path: path, FileName: &fileName, Hash: songHash})
|
||||
|
||||
Reference in New Issue
Block a user