From eee8008bb2ffe8e3b112f9c52b422db5b142d66b Mon Sep 17 00:00:00 2001 From: Kukks Date: Thu, 28 Oct 2021 12:23:21 +0200 Subject: [PATCH] Make sure migration for apps does not crash --- BTCPayServer/Hosting/MigrationStartupTask.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/BTCPayServer/Hosting/MigrationStartupTask.cs b/BTCPayServer/Hosting/MigrationStartupTask.cs index d10913822..bc83253c3 100644 --- a/BTCPayServer/Hosting/MigrationStartupTask.cs +++ b/BTCPayServer/Hosting/MigrationStartupTask.cs @@ -192,7 +192,7 @@ namespace BTCPayServer.Hosting private async Task MigrateAppCustomOption() { await using var ctx = _DBContextFactory.CreateContext(); - foreach (var app in await ctx.Apps.AsQueryable().ToArrayAsync()) + foreach (var app in await ctx.Apps.Include(data => data.StoreData).AsQueryable().ToArrayAsync()) { ViewPointOfSaleViewModel.Item[] items; string newTemplate; @@ -200,6 +200,11 @@ namespace BTCPayServer.Hosting { case nameof(AppType.Crowdfund): var settings1 = app.GetSettings(); + if (string.IsNullOrEmpty(settings1.TargetCurrency)) + { + settings1.TargetCurrency = app.StoreData.GetStoreBlob().DefaultCurrency; + app.SetSettings(settings1); + } items = _appService.Parse(settings1.PerksTemplate, settings1.TargetCurrency); newTemplate = _appService.SerializeTemplate(items); if (settings1.PerksTemplate != newTemplate) @@ -212,6 +217,11 @@ namespace BTCPayServer.Hosting case nameof(AppType.PointOfSale): var settings2 = app.GetSettings(); + if (string.IsNullOrEmpty(settings2.Currency)) + { + settings2.Currency = app.StoreData.GetStoreBlob().DefaultCurrency; + app.SetSettings(settings2); + } items = _appService.Parse(settings2.Template, settings2.Currency); newTemplate = _appService.SerializeTemplate(items); if (settings2.Template != newTemplate)