diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index abf01ab9d..46bbe42c6 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -2,7 +2,7 @@ Exe netcoreapp2.1 - 1.0.2.50 + 1.0.2.51 NU1701,CA1816,CA1308,CA1810,CA2208 diff --git a/BTCPayServer/Extensions.cs b/BTCPayServer/Extensions.cs index fc63af246..f7a8f5e9b 100644 --- a/BTCPayServer/Extensions.cs +++ b/BTCPayServer/Extensions.cs @@ -31,6 +31,7 @@ using System.Security.Claims; using System.Globalization; using BTCPayServer.Services; using BTCPayServer.Data; +using Microsoft.EntityFrameworkCore.Infrastructure; namespace BTCPayServer { @@ -82,6 +83,15 @@ namespace BTCPayServer return activeProvider != "Microsoft.EntityFrameworkCore.Sqlite"; } + public static bool SupportDropForeignKey(this Microsoft.EntityFrameworkCore.Migrations.Migration migration, string activeProvider) + { + return activeProvider != "Microsoft.EntityFrameworkCore.Sqlite"; + } + public static bool SupportDropForeignKey(this DatabaseFacade facade) + { + return facade.ProviderName != "Microsoft.EntityFrameworkCore.Sqlite"; + } + public static async Task> GetTransactions(this BTCPayWallet client, uint256[] hashes, CancellationToken cts = default(CancellationToken)) { hashes = hashes.Distinct().ToArray(); diff --git a/BTCPayServer/HostedServices/MigratorHostedService.cs b/BTCPayServer/HostedServices/MigratorHostedService.cs index 8032af09a..2778713bf 100644 --- a/BTCPayServer/HostedServices/MigratorHostedService.cs +++ b/BTCPayServer/HostedServices/MigratorHostedService.cs @@ -43,7 +43,7 @@ namespace BTCPayServer.HostedServices var settings = (await _Settings.GetSettingAsync()) ?? new MigrationSettings(); if (!settings.DeprecatedLightningConnectionStringCheck) { - await DepracatedLightningConnectionStringCheck(); + await DeprecatedLightningConnectionStringCheck(); settings.DeprecatedLightningConnectionStringCheck = true; await _Settings.UpdateSetting(settings); } @@ -54,7 +54,7 @@ namespace BTCPayServer.HostedServices await _Settings.UpdateSetting(settings); } } - catch(Exception ex) + catch (Exception ex) { Logs.PayServer.LogError(ex, "Error on the MigratorHostedService"); throw; @@ -65,6 +65,8 @@ namespace BTCPayServer.HostedServices { using (var ctx = _DBContextFactory.CreateContext()) { + if (!ctx.Database.SupportDropForeignKey()) + return; foreach (var store in await ctx.Stores.Where(s => s.UserStores.Count() == 0).ToArrayAsync()) { ctx.Stores.Remove(store); @@ -73,7 +75,7 @@ namespace BTCPayServer.HostedServices } } - private async Task DepracatedLightningConnectionStringCheck() + private async Task DeprecatedLightningConnectionStringCheck() { using (var ctx = _DBContextFactory.CreateContext()) { diff --git a/BTCPayServer/Migrations/20180719095626_CanDeleteStores.cs b/BTCPayServer/Migrations/20180719095626_CanDeleteStores.cs index 0f8de298c..f4dd95eff 100644 --- a/BTCPayServer/Migrations/20180719095626_CanDeleteStores.cs +++ b/BTCPayServer/Migrations/20180719095626_CanDeleteStores.cs @@ -6,89 +6,92 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.DropForeignKey( + if (this.SupportDropForeignKey(migrationBuilder.ActiveProvider)) + { + migrationBuilder.DropForeignKey( name: "FK_AddressInvoices_Invoices_InvoiceDataId", table: "AddressInvoices"); - migrationBuilder.DropForeignKey( - name: "FK_Apps_Stores_StoreDataId", - table: "Apps"); + migrationBuilder.DropForeignKey( + name: "FK_Apps_Stores_StoreDataId", + table: "Apps"); - migrationBuilder.DropForeignKey( - name: "FK_Invoices_Stores_StoreDataId", - table: "Invoices"); + migrationBuilder.DropForeignKey( + name: "FK_Invoices_Stores_StoreDataId", + table: "Invoices"); - migrationBuilder.DropForeignKey( - name: "FK_Payments_Invoices_InvoiceDataId", - table: "Payments"); + migrationBuilder.DropForeignKey( + name: "FK_Payments_Invoices_InvoiceDataId", + table: "Payments"); - migrationBuilder.DropForeignKey( - name: "FK_RefundAddresses_Invoices_InvoiceDataId", - table: "RefundAddresses"); + migrationBuilder.DropForeignKey( + name: "FK_RefundAddresses_Invoices_InvoiceDataId", + table: "RefundAddresses"); - migrationBuilder.AddForeignKey( - name: "FK_AddressInvoices_Invoices_InvoiceDataId", - table: "AddressInvoices", - column: "InvoiceDataId", - principalTable: "Invoices", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_AddressInvoices_Invoices_InvoiceDataId", + table: "AddressInvoices", + column: "InvoiceDataId", + principalTable: "Invoices", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.AddForeignKey( - name: "FK_ApiKeys_Stores_StoreId", - table: "ApiKeys", - column: "StoreId", - principalTable: "Stores", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_ApiKeys_Stores_StoreId", + table: "ApiKeys", + column: "StoreId", + principalTable: "Stores", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.AddForeignKey( - name: "FK_Apps_Stores_StoreDataId", - table: "Apps", - column: "StoreDataId", - principalTable: "Stores", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_Apps_Stores_StoreDataId", + table: "Apps", + column: "StoreDataId", + principalTable: "Stores", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.AddForeignKey( - name: "FK_Invoices_Stores_StoreDataId", - table: "Invoices", - column: "StoreDataId", - principalTable: "Stores", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_Invoices_Stores_StoreDataId", + table: "Invoices", + column: "StoreDataId", + principalTable: "Stores", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.AddForeignKey( - name: "FK_PairedSINData_Stores_StoreDataId", - table: "PairedSINData", - column: "StoreDataId", - principalTable: "Stores", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_PairedSINData_Stores_StoreDataId", + table: "PairedSINData", + column: "StoreDataId", + principalTable: "Stores", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.AddForeignKey( - name: "FK_Payments_Invoices_InvoiceDataId", - table: "Payments", - column: "InvoiceDataId", - principalTable: "Invoices", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_Payments_Invoices_InvoiceDataId", + table: "Payments", + column: "InvoiceDataId", + principalTable: "Invoices", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.AddForeignKey( - name: "FK_PendingInvoices_Invoices_Id", - table: "PendingInvoices", - column: "Id", - principalTable: "Invoices", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_PendingInvoices_Invoices_Id", + table: "PendingInvoices", + column: "Id", + principalTable: "Invoices", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.AddForeignKey( - name: "FK_RefundAddresses_Invoices_InvoiceDataId", - table: "RefundAddresses", - column: "InvoiceDataId", - principalTable: "Invoices", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_RefundAddresses_Invoices_InvoiceDataId", + table: "RefundAddresses", + column: "InvoiceDataId", + principalTable: "Invoices", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer/Services/Stores/StoreRepository.cs b/BTCPayServer/Services/Stores/StoreRepository.cs index dd6efabc2..f85deb6ed 100644 --- a/BTCPayServer/Services/Stores/StoreRepository.cs +++ b/BTCPayServer/Services/Stores/StoreRepository.cs @@ -174,6 +174,8 @@ namespace BTCPayServer.Services.Stores { using (var ctx = _ContextFactory.CreateContext()) { + if (!ctx.Database.SupportDropForeignKey()) + return false; var store = await ctx.Stores.FindAsync(storeId); if (store == null) return false;