fix: stored procedure and database cleanup fix (also fixes file copying)
All checks were successful
Update changelog / changelog (push) Successful in 26s

This commit is contained in:
2026-01-27 07:52:20 +01:00
parent 17b8bafccd
commit 6a92451776
3 changed files with 18 additions and 10 deletions

View File

@@ -13,7 +13,7 @@ public partial class _00000000000000_StoredProcedure : Migration
AS $$ AS $$
BEGIN BEGIN
DELETE FROM "Songs" DELETE FROM "Songs"
WHERE "State" = 0; WHERE "State" = 1;
COMMIT; COMMIT;
END; END;

View File

@@ -44,9 +44,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="Mapping\" /> <Folder Include="Mapping\" />
<Folder Include="DTOs\" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -349,7 +349,8 @@ public class Cli
{ {
File.Copy( File.Copy(
Path.Combine(currentPath, "Assets", "vinyl.png"), Path.Combine(currentPath, "Assets", "vinyl.png"),
Path.Combine(newMusicThumbnailPath, "default.png") Path.Combine(newMusicThumbnailPath, "default.png"),
true
); );
break; break;
} }
@@ -357,7 +358,7 @@ public class Cli
currentPath = Path.Combine(currentPath, ".."); currentPath = Path.Combine(currentPath, "..");
if (i == 5) Console.WriteLine("\n" + if (i == 5) Console.WriteLine("\n" +
"Error: Could not determine content root path. \n" + "[Error] Could not determine content root path. \n" +
"Please place Assets/vinyl.png in your thumbnail path directory manually\n" + "Please place Assets/vinyl.png in your thumbnail path directory manually\n" +
"and rename it to default.png."); "and rename it to default.png.");
} }
@@ -385,7 +386,10 @@ public class Cli
int rowsAffected = 0; int rowsAffected = 0;
// Retrieve orphaned songs // Retrieve orphaned songs
List<Song> orphanedSongs = db.Songs.Where(s => s.State == 1).ToList(); List<Song> orphanedSongs = db.Songs
.Where(s => s.State == 1)
.Include(s => s.Album)
.ToList();
// Ask if it's alright to remove them // Ask if it's alright to remove them
// and related listening data permanently // and related listening data permanently
@@ -413,11 +417,13 @@ public class Cli
// TODO: Remove song images if not used by any other resource // TODO: Remove song images if not used by any other resource
// ... // ...
db.SaveChanges();
} }
// Perform cleanup with stored procedure // Perform cleanup with stored procedure
rowsAffected += db.Database.ExecuteSqlRaw("CALL song_cleanup()"); db.Database.ExecuteSqlRaw("CALL song_cleanup()");
// rowsAffected += songs.Count; rowsAffected += orphanedSongs.Count;
} }
} }
else Console.WriteLine("No orphaned songs found."); else Console.WriteLine("No orphaned songs found.");
@@ -434,13 +440,17 @@ public class Cli
{ {
db.Albums.RemoveRange(orphanedAlbums); db.Albums.RemoveRange(orphanedAlbums);
rowsAffected += orphanedAlbums.Count; rowsAffected += orphanedAlbums.Count;
db.SaveChanges();
} }
} }
else Console.WriteLine("No orphaned albums found."); else Console.WriteLine("No orphaned albums found.");
// Retrieve orphaned artists (artists with no songs AND albums) // Retrieve orphaned artists (artists with no songs AND albums)
List<Artist> orphanedArtists = db.Artists.Where(a => a.Songs.Count == 0 && a.Albums.Count == 0).ToList(); List<Artist> orphanedArtists = db.Artists
Artist? unknownArtist = db.Artists.FirstOrDefault(a => a.NormalizedName == "[unknown artist]"); .Where(a => a.Songs.Count == 0 && a.Albums.Count == 0)
.ToList();
Artist? unknownArtist = db.Artists
.FirstOrDefault(a => a.NormalizedName == "[unknown artist]");
// Account for the [Unknown Artist], // Account for the [Unknown Artist],
// which is a meta-artist and shall // which is a meta-artist and shall