Fixed a critical bug where registration was broken for first time flow. Refactored how backup before migrations occured such that it now puts the db in temp. The db will be deleted automatically that night. (#900)

This commit is contained in:
Joseph Milazzo 2022-01-05 15:07:54 -08:00 committed by GitHub
parent 1590e4e13d
commit 6006faa574
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 61 deletions

View file

@ -134,7 +134,7 @@ namespace API
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IBackgroundJobClient backgroundJobs, IWebHostEnvironment env,
IHostApplicationLifetime applicationLifetime, IServiceProvider serviceProvider, ICacheService cacheService,
IDirectoryService directoryService, IUnitOfWork unitOfWork, IBackupService backupService)
IDirectoryService directoryService, IUnitOfWork unitOfWork, IBackupService backupService, IImageService imageService)
{
// Apply Migrations
@ -144,26 +144,44 @@ namespace API
{
// Apply all migrations on startup
// If we have pending migrations, make a backup first
var isDocker = new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker;
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
var context = serviceProvider.GetRequiredService<DataContext>();
var pendingMigrations = await context.Database.GetPendingMigrationsAsync();
if (pendingMigrations.Any())
{
logger.LogInformation("Performing backup as migrations are needed");
await backupService.BackupDatabase();
}
await context.Database.MigrateAsync();
// var pendingMigrations = await context.Database.GetPendingMigrationsAsync();
// if (pendingMigrations.Any())
// {
// logger.LogInformation("Performing backup as migrations are needed");
// await backupService.BackupDatabase();
// }
//
// await context.Database.MigrateAsync();
// var roleManager = serviceProvider.GetRequiredService<RoleManager<AppRole>>();
//
// await Seed.SeedRoles(roleManager);
// await Seed.SeedSettings(context, directoryService);
// await Seed.SeedUserApiKeys(context);
await MigrateBookmarks.Migrate(directoryService, unitOfWork,
logger, cacheService);
var roleManager = serviceProvider.GetRequiredService<RoleManager<AppRole>>();
await Seed.SeedRoles(roleManager);
await Seed.SeedSettings(context, directoryService);
await Seed.SeedUserApiKeys(context);
var requiresCoverImageMigration = !Directory.Exists(directoryService.CoverImageDirectory);
try
{
// If this is a new install, tables wont exist yet
if (requiresCoverImageMigration)
{
MigrateCoverImages.ExtractToImages(context, directoryService, imageService);
}
}
catch (Exception)
{
requiresCoverImageMigration = false;
}
if (requiresCoverImageMigration)
{
await MigrateCoverImages.UpdateDatabaseWithImages(context, directoryService);
}
}).GetAwaiter()
.GetResult();
}