From 3ed83a276fef404ad2228bbba952eda31ed102f2 Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Tue, 2 Mar 2021 12:32:14 -0600 Subject: [PATCH] fix database migration (#35) --- .../Migrations/20210226132335_Update_MovieMetadata.cs | 2 +- ErsatzTV/Extensions/HostExtensions.cs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ErsatzTV.Infrastructure/Migrations/20210226132335_Update_MovieMetadata.cs b/ErsatzTV.Infrastructure/Migrations/20210226132335_Update_MovieMetadata.cs index be6eda800..bab85ad5e 100644 --- a/ErsatzTV.Infrastructure/Migrations/20210226132335_Update_MovieMetadata.cs +++ b/ErsatzTV.Infrastructure/Migrations/20210226132335_Update_MovieMetadata.cs @@ -11,7 +11,7 @@ namespace ErsatzTV.Infrastructure.Migrations migrationBuilder.Sql( @$"INSERT INTO NewMovieMetadata (Outline, Plot, Tagline, MovieId, MetadataKind, Title, OriginalTitle, SortTitle, ReleaseDate, DateAdded, DateUpdated) -SELECT mm.Outline, mm.Plot, mm.Tagline, m.Id, mm.Source, mm.Title, null, mm.SortTitle, mm.Premiered, '{now}', mm.LastWriteTime +SELECT mm.Outline, mm.Plot, mm.Tagline, m.Id, mm.Source, mm.Title, null, mm.SortTitle, mm.Premiered, '{now}', IFNULL(mm.LastWriteTime, '0001-01-01 00:00:00') FROM MovieMetadata mm INNER JOIN Movie m ON mm.MovieId = m.Id"); } diff --git a/ErsatzTV/Extensions/HostExtensions.cs b/ErsatzTV/Extensions/HostExtensions.cs index a193940c1..bce49bcbb 100644 --- a/ErsatzTV/Extensions/HostExtensions.cs +++ b/ErsatzTV/Extensions/HostExtensions.cs @@ -33,7 +33,13 @@ namespace ErsatzTV.Extensions .Bind(services => Try(GetDbContext(services))) .Bind(ctx => Try(Migrate(ctx, scope.ServiceProvider))) .Bind(ctx => Try(InitializeDb(ctx))) - .IfFail(ex => LogException(ex, "Error occured while seeding database", scope.ServiceProvider)); + .IfFail( + ex => + { + LogException(ex, "Error occured while migrating database; shutting down.", scope.ServiceProvider); + Environment.Exit(13); + return unit; + }); private static Unit CleanCache(IServiceScope scope) => Try(() => scope.ServiceProvider)