fix: assign unknown album to unknown artist, changes in migration logic
All checks were successful
Update changelog / changelog (push) Successful in 27s
All checks were successful
Update changelog / changelog (push) Successful in 27s
This commit is contained in:
@@ -84,25 +84,34 @@ public class Seeder
|
||||
if (adminCount == 0 && userCount > 0)
|
||||
Console.WriteLine("[Warn]: No admin accounts exist. Consider creating one with `Shadow addUser`.\n");
|
||||
|
||||
// Ensure [Unknown Album], [Unknown Artist] exist
|
||||
Album unknownAlbum = db.Albums.FirstOrDefault(a => a.Name == "[Unknown Album]") ?? new Album()
|
||||
{
|
||||
Name = "[Unknown Album]",
|
||||
Uri = "00000000000000000000000000000000"
|
||||
};
|
||||
|
||||
// Ensure [Unknown Artist], [Unknown Album] exist
|
||||
Artist unknownArtist = db.Artists.FirstOrDefault(a => a.Name == "[Unknown Artist]") ?? new Artist()
|
||||
{
|
||||
Name = "[Unknown Artist]",
|
||||
NormalizedName = "[unknown artist]"
|
||||
};
|
||||
|
||||
// Update works both as an Add and Update.
|
||||
db.Update(unknownArtist);
|
||||
db.SaveChanges();
|
||||
|
||||
Album unknownAlbum = db.Albums.FirstOrDefault(a => a.Name == "[Unknown Album]") ?? new Album()
|
||||
{
|
||||
Name = "[Unknown Album]",
|
||||
Uri = "00000000000000000000000000000000",
|
||||
Artist = unknownArtist
|
||||
};
|
||||
db.Update(unknownAlbum);
|
||||
|
||||
// Add [Unknown Album] to [Unknown Artist]
|
||||
unknownArtist.Albums.Add(unknownAlbum);
|
||||
db.Update(unknownArtist);
|
||||
|
||||
runs ??= new Global() { Key = "runs", Value = "0" };
|
||||
if (int.TryParse(runs.Value, out int runsInt))
|
||||
runs.Value = $"{runsInt + 1}";
|
||||
|
||||
// UpdateRange works both as an Add and Update.
|
||||
db.UpdateRange(unknownAlbum, unknownArtist, runs);
|
||||
db.Update(runs);
|
||||
db.SaveChanges();
|
||||
|
||||
return shutdown;
|
||||
@@ -118,10 +127,9 @@ public class Seeder
|
||||
List<string> appliedMigrations = dbContext.Database.GetAppliedMigrations().ToList();
|
||||
|
||||
bool hasMissingMigrations = availableMigrations.Count > appliedMigrations.Count;
|
||||
bool doMigrationsMatch = availableMigrations.SequenceEqual(appliedMigrations);
|
||||
if (hasMissingMigrations)
|
||||
{
|
||||
bool userMigrationConsent = false;
|
||||
bool userMigrationConsent = true; // apply migrations by default
|
||||
Console.WriteLine("\n" +
|
||||
"========================================\n" +
|
||||
"[Warn] Database migrations missing!\n" +
|
||||
@@ -129,19 +137,30 @@ public class Seeder
|
||||
if (appliedMigrations.Count == 0)
|
||||
{
|
||||
Console.WriteLine( "Empty database detected. Applying migrations is recommended, and required if this is the first run of Shadow.");
|
||||
userMigrationConsent = Cli.YesNoPrompt("Do you want to apply migrations automatically? [Y/n]: ", true);
|
||||
// userMigrationConsent = Cli.YesNoPrompt("Do you want to apply migrations automatically? [Y/n]: ", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Detected existing {appliedMigrations.Count} migrations. Backing up the database before applying migrations is recommended.");
|
||||
userMigrationConsent = Cli.YesNoPrompt("Do you want to apply migrations automatically? [y/N]: ", false);
|
||||
Console.WriteLine($"Detected existing {appliedMigrations.Count} migrations. Backing up the database before applying migrations is recommended.\n" +
|
||||
"Waiting 15 seconds.");
|
||||
Thread.Sleep(15_000);
|
||||
// userMigrationConsent = Cli.YesNoPrompt("Do you want to apply migrations automatically? [y/N]: ", false);
|
||||
}
|
||||
|
||||
// Do we have user permission to perform migration?
|
||||
if (userMigrationConsent)
|
||||
{
|
||||
dbContext.Database.Migrate();
|
||||
dbContext.SaveChanges();
|
||||
try
|
||||
{
|
||||
dbContext.Database.Migrate();
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error! Unable to process migration automatically.\n" +
|
||||
$"Error message was: {e.Message}\n\n" +
|
||||
$"Consider ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user