From 8947f13dbea0585f73ddca48571d9bead50b5fc4 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Mon, 4 Jan 2021 22:35:00 -0600 Subject: [PATCH] Deleting legacy DBriize database if present --- .../HostedServices/DbMigrationsHostedService.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/BTCPayServer/HostedServices/DbMigrationsHostedService.cs b/BTCPayServer/HostedServices/DbMigrationsHostedService.cs index 032c33601..3afff9e20 100644 --- a/BTCPayServer/HostedServices/DbMigrationsHostedService.cs +++ b/BTCPayServer/HostedServices/DbMigrationsHostedService.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Threading.Tasks; +using BTCPayServer.Configuration; using BTCPayServer.Data; using BTCPayServer.Services; using BTCPayServer.Services.Invoices; @@ -16,12 +18,14 @@ namespace BTCPayServer.HostedServices private readonly InvoiceRepository _invoiceRepository; private readonly SettingsRepository _settingsRepository; private readonly ApplicationDbContextFactory _dbContextFactory; + private readonly DataDirectories _datadirs; - public DbMigrationsHostedService(InvoiceRepository invoiceRepository, SettingsRepository settingsRepository, ApplicationDbContextFactory dbContextFactory) + public DbMigrationsHostedService(InvoiceRepository invoiceRepository, SettingsRepository settingsRepository, ApplicationDbContextFactory dbContextFactory, DataDirectories datadirs) { _invoiceRepository = invoiceRepository; _settingsRepository = settingsRepository; _dbContextFactory = dbContextFactory; + _datadirs = datadirs; } @@ -43,6 +47,14 @@ namespace BTCPayServer.HostedServices private async Task MigratedInvoiceTextSearchToDb(int startFromPage) { + // deleting legacy DBriize database if present + var dbpath = Path.Combine(_datadirs.DataDir, "InvoiceDB"); + if (Directory.Exists(dbpath)) + { + Directory.Delete(dbpath, true); + } + + // migrate data to new table using invoices from database using var ctx = _dbContextFactory.CreateContext(); var invoiceQuery = new InvoiceQuery { IncludeArchived = true };