From 8bb4ceaaac70de570f22a6bb9522bc0a80930657 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Tue, 7 May 2024 09:21:49 +0900 Subject: [PATCH] Remove dead code from multi db support (#5971) --- ...20230529135505_WebhookDeliveriesCleanup.cs | 101 +++++++++--------- .../20231121031609_removecurrentrefund.cs | 21 ++-- .../20231219031609_appssettingstojson.cs | 5 +- ...00000_FixWalletObjectsWithEmptyWalletId.cs | 5 +- ...29000000_PayoutAndPullPaymentToJsonBlob.cs | 9 +- ...92905_AddManagerAndEmployeeToStoreRoles.cs | 35 +++--- .../20240304003640_addinvoicecolumns.cs | 2 +- .../20240317024757_payments_refactor.cs | 14 ++- ...20240405052858_cleanup_address_invoices.cs | 5 +- BTCPayServer/Hosting/MigrationStartupTask.cs | 16 --- BTCPayServer/Services/MigrationSettings.cs | 1 - BTCPayServer/Services/WalletRepository.cs | 98 +++-------------- 12 files changed, 98 insertions(+), 214 deletions(-) diff --git a/BTCPayServer.Data/Migrations/20230529135505_WebhookDeliveriesCleanup.cs b/BTCPayServer.Data/Migrations/20230529135505_WebhookDeliveriesCleanup.cs index 021208a7d..ee63e3c31 100644 --- a/BTCPayServer.Data/Migrations/20230529135505_WebhookDeliveriesCleanup.cs +++ b/BTCPayServer.Data/Migrations/20230529135505_WebhookDeliveriesCleanup.cs @@ -17,62 +17,59 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (migrationBuilder.IsNpgsql()) + migrationBuilder.Sql("DROP TABLE IF EXISTS \"InvoiceWebhookDeliveries\", \"WebhookDeliveries\";"); + + migrationBuilder.CreateTable( + name: "WebhookDeliveries", + columns: table => new { - migrationBuilder.Sql("DROP TABLE IF EXISTS \"InvoiceWebhookDeliveries\", \"WebhookDeliveries\";"); - - migrationBuilder.CreateTable( - name: "WebhookDeliveries", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false), - WebhookId = table.Column(type: "TEXT", nullable: false), - Timestamp = table.Column(type: "timestamp with time zone", nullable: false), - Pruned = table.Column(type: "BOOLEAN", nullable: false), - Blob = table.Column(type: "JSONB", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_WebhookDeliveries", x => x.Id); - table.ForeignKey( - name: "FK_WebhookDeliveries_Webhooks_WebhookId", - column: x => x.WebhookId, - principalTable: "Webhooks", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); + Id = table.Column(type: "TEXT", nullable: false), + WebhookId = table.Column(type: "TEXT", nullable: false), + Timestamp = table.Column(type: "timestamp with time zone", nullable: false), + Pruned = table.Column(type: "BOOLEAN", nullable: false), + Blob = table.Column(type: "JSONB", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_WebhookDeliveries", x => x.Id); + table.ForeignKey( + name: "FK_WebhookDeliveries_Webhooks_WebhookId", + column: x => x.WebhookId, + principalTable: "Webhooks", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); - migrationBuilder.CreateIndex( - name: "IX_WebhookDeliveries_WebhookId", - table: "WebhookDeliveries", - column: "WebhookId"); - migrationBuilder.Sql("CREATE INDEX \"IX_WebhookDeliveries_Timestamp\" ON \"WebhookDeliveries\"(\"Timestamp\") WHERE \"Pruned\" IS FALSE"); + migrationBuilder.CreateIndex( + name: "IX_WebhookDeliveries_WebhookId", + table: "WebhookDeliveries", + column: "WebhookId"); + migrationBuilder.Sql("CREATE INDEX \"IX_WebhookDeliveries_Timestamp\" ON \"WebhookDeliveries\"(\"Timestamp\") WHERE \"Pruned\" IS FALSE"); - migrationBuilder.CreateTable( - name: "InvoiceWebhookDeliveries", - columns: table => new - { - InvoiceId = table.Column(type: "TEXT", nullable: false), - DeliveryId = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_InvoiceWebhookDeliveries", x => new { x.InvoiceId, x.DeliveryId }); - table.ForeignKey( - name: "FK_InvoiceWebhookDeliveries_WebhookDeliveries_DeliveryId", - column: x => x.DeliveryId, - principalTable: "WebhookDeliveries", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_InvoiceWebhookDeliveries_Invoices_InvoiceId", - column: x => x.InvoiceId, - principalTable: "Invoices", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - } + migrationBuilder.CreateTable( + name: "InvoiceWebhookDeliveries", + columns: table => new + { + InvoiceId = table.Column(type: "TEXT", nullable: false), + DeliveryId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_InvoiceWebhookDeliveries", x => new { x.InvoiceId, x.DeliveryId }); + table.ForeignKey( + name: "FK_InvoiceWebhookDeliveries_WebhookDeliveries_DeliveryId", + column: x => x.DeliveryId, + principalTable: "WebhookDeliveries", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_InvoiceWebhookDeliveries_Invoices_InvoiceId", + column: x => x.InvoiceId, + principalTable: "Invoices", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20231121031609_removecurrentrefund.cs b/BTCPayServer.Data/Migrations/20231121031609_removecurrentrefund.cs index 956df0d34..93f7b8b9c 100644 --- a/BTCPayServer.Data/Migrations/20231121031609_removecurrentrefund.cs +++ b/BTCPayServer.Data/Migrations/20231121031609_removecurrentrefund.cs @@ -13,20 +13,17 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (migrationBuilder.IsNpgsql()) - { - migrationBuilder.DropForeignKey( - name: "FK_Invoices_Refunds_Id_CurrentRefundId", - table: "Invoices"); + migrationBuilder.DropForeignKey( + name: "FK_Invoices_Refunds_Id_CurrentRefundId", + table: "Invoices"); - migrationBuilder.DropIndex( - name: "IX_Invoices_Id_CurrentRefundId", - table: "Invoices"); + migrationBuilder.DropIndex( + name: "IX_Invoices_Id_CurrentRefundId", + table: "Invoices"); - migrationBuilder.DropColumn( - name: "CurrentRefundId", - table: "Invoices"); - } + migrationBuilder.DropColumn( + name: "CurrentRefundId", + table: "Invoices"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20231219031609_appssettingstojson.cs b/BTCPayServer.Data/Migrations/20231219031609_appssettingstojson.cs index e56ed3c03..04ed8d836 100644 --- a/BTCPayServer.Data/Migrations/20231219031609_appssettingstojson.cs +++ b/BTCPayServer.Data/Migrations/20231219031609_appssettingstojson.cs @@ -13,10 +13,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (migrationBuilder.IsNpgsql()) - { - migrationBuilder.Sql("ALTER TABLE \"Apps\" ALTER COLUMN \"Settings\" TYPE JSONB USING \"Settings\"::JSONB"); - } + migrationBuilder.Sql("ALTER TABLE \"Apps\" ALTER COLUMN \"Settings\" TYPE JSONB USING \"Settings\"::JSONB"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20240220000000_FixWalletObjectsWithEmptyWalletId.cs b/BTCPayServer.Data/Migrations/20240220000000_FixWalletObjectsWithEmptyWalletId.cs index 62fba6e35..5527a0db0 100644 --- a/BTCPayServer.Data/Migrations/20240220000000_FixWalletObjectsWithEmptyWalletId.cs +++ b/BTCPayServer.Data/Migrations/20240220000000_FixWalletObjectsWithEmptyWalletId.cs @@ -13,10 +13,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (migrationBuilder.IsNpgsql()) - { - migrationBuilder.Sql("DELETE FROM \"WalletObjects\" WHERE \"WalletId\"='';"); - } + migrationBuilder.Sql("DELETE FROM \"WalletObjects\" WHERE \"WalletId\"='';"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20240229000000_PayoutAndPullPaymentToJsonBlob.cs b/BTCPayServer.Data/Migrations/20240229000000_PayoutAndPullPaymentToJsonBlob.cs index f65de372f..1380a3aff 100644 --- a/BTCPayServer.Data/Migrations/20240229000000_PayoutAndPullPaymentToJsonBlob.cs +++ b/BTCPayServer.Data/Migrations/20240229000000_PayoutAndPullPaymentToJsonBlob.cs @@ -13,12 +13,9 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (migrationBuilder.IsNpgsql()) - { - migrationBuilder.Sql("ALTER TABLE \"Payouts\" ALTER COLUMN \"Blob\" TYPE JSONB USING regexp_replace(convert_from(\"Blob\",'UTF8'), '\\\\u0000', '', 'g')::JSONB"); - migrationBuilder.Sql("ALTER TABLE \"Payouts\" ALTER COLUMN \"Proof\" TYPE JSONB USING regexp_replace(convert_from(\"Proof\",'UTF8'), '\\\\u0000', '', 'g')::JSONB"); - migrationBuilder.Sql("ALTER TABLE \"PullPayments\" ALTER COLUMN \"Blob\" TYPE JSONB USING regexp_replace(convert_from(\"Blob\",'UTF8'), '\\\\u0000', '', 'g')::JSONB"); - } + migrationBuilder.Sql("ALTER TABLE \"Payouts\" ALTER COLUMN \"Blob\" TYPE JSONB USING regexp_replace(convert_from(\"Blob\",'UTF8'), '\\\\u0000', '', 'g')::JSONB"); + migrationBuilder.Sql("ALTER TABLE \"Payouts\" ALTER COLUMN \"Proof\" TYPE JSONB USING regexp_replace(convert_from(\"Proof\",'UTF8'), '\\\\u0000', '', 'g')::JSONB"); + migrationBuilder.Sql("ALTER TABLE \"PullPayments\" ALTER COLUMN \"Blob\" TYPE JSONB USING regexp_replace(convert_from(\"Blob\",'UTF8'), '\\\\u0000', '', 'g')::JSONB"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20240229092905_AddManagerAndEmployeeToStoreRoles.cs b/BTCPayServer.Data/Migrations/20240229092905_AddManagerAndEmployeeToStoreRoles.cs index 6a93968de..7ac99d5fc 100644 --- a/BTCPayServer.Data/Migrations/20240229092905_AddManagerAndEmployeeToStoreRoles.cs +++ b/BTCPayServer.Data/Migrations/20240229092905_AddManagerAndEmployeeToStoreRoles.cs @@ -1,4 +1,4 @@ -using BTCPayServer.Data; +using BTCPayServer.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; @@ -11,25 +11,17 @@ namespace BTCPayServer.Migrations [DbContext(typeof(ApplicationDbContext))] [Migration("20240229092905_AddManagerAndEmployeeToStoreRoles")] public partial class AddManagerAndEmployeeToStoreRoles : Migration - { - object GetPermissionsData(MigrationBuilder migrationBuilder, string[] permissions) - { - return migrationBuilder.IsNpgsql() - ? permissions - : JsonConvert.SerializeObject(permissions); - } - + { protected override void Up(MigrationBuilder migrationBuilder) { - var permissionsType = migrationBuilder.IsNpgsql() ? "TEXT[]" : "TEXT"; migrationBuilder.InsertData( "StoreRoles", columns: new[] { "Id", "Role", "Permissions" }, - columnTypes: new[] { "TEXT", "TEXT", permissionsType }, + columnTypes: new[] { "TEXT", "TEXT", "TEXT[]" }, values: new object[,] { { - "Manager", "Manager", GetPermissionsData(migrationBuilder, new[] + "Manager", "Manager", new[] { "btcpay.store.canviewstoresettings", "btcpay.store.canmodifyinvoices", @@ -37,17 +29,17 @@ namespace BTCPayServer.Migrations "btcpay.store.canmodifypaymentrequests", "btcpay.store.canmanagepullpayments", "btcpay.store.canmanagepayouts" - }) + } }, { - "Employee", "Employee", GetPermissionsData(migrationBuilder, new[] + "Employee", "Employee", new[] { "btcpay.store.canmodifyinvoices", "btcpay.store.canmodifypaymentrequests", "btcpay.store.cancreatenonapprovedpullpayments", "btcpay.store.canviewpayouts", "btcpay.store.canviewpullpayments" - }) + } } }); @@ -57,16 +49,16 @@ namespace BTCPayServer.Migrations keyColumnTypes: new[] { "TEXT" }, keyValues: new[] { "Guest" }, columns: new[] { "Permissions" }, - columnTypes: new[] { permissionsType }, + columnTypes: new[] { "TEXT[]" }, values: new object[] { - GetPermissionsData(migrationBuilder, new[] + new[] { "btcpay.store.canmodifyinvoices", "btcpay.store.canviewpaymentrequests", "btcpay.store.canviewpullpayments", "btcpay.store.canviewpayouts" - }) + } }); } @@ -75,23 +67,22 @@ namespace BTCPayServer.Migrations migrationBuilder.DeleteData("StoreRoles", "Id", "Manager"); migrationBuilder.DeleteData("StoreRoles", "Id", "Employee"); - var permissionsType = migrationBuilder.IsNpgsql() ? "TEXT[]" : "TEXT"; migrationBuilder.UpdateData( "StoreRoles", keyColumns: new[] { "Id" }, keyColumnTypes: new[] { "TEXT" }, keyValues: new[] { "Guest" }, columns: new[] { "Permissions" }, - columnTypes: new[] { permissionsType }, + columnTypes: new[] { "TEXT[]" }, values: new object[] { - GetPermissionsData(migrationBuilder, new[] + new[] { "btcpay.store.canviewstoresettings", "btcpay.store.canmodifyinvoices", "btcpay.store.canviewcustodianaccounts", "btcpay.store.candeposittocustodianaccount" - }) + } }); } } diff --git a/BTCPayServer.Data/Migrations/20240304003640_addinvoicecolumns.cs b/BTCPayServer.Data/Migrations/20240304003640_addinvoicecolumns.cs index bf398e493..88c2a334f 100644 --- a/BTCPayServer.Data/Migrations/20240304003640_addinvoicecolumns.cs +++ b/BTCPayServer.Data/Migrations/20240304003640_addinvoicecolumns.cs @@ -18,7 +18,7 @@ namespace BTCPayServer.Migrations migrationBuilder.AddColumn( name: "Amount", table: "Invoices", - type: migrationBuilder.IsNpgsql() ? "NUMERIC" : "TEXT", + type: "NUMERIC", nullable: true); migrationBuilder.AddColumn( diff --git a/BTCPayServer.Data/Migrations/20240317024757_payments_refactor.cs b/BTCPayServer.Data/Migrations/20240317024757_payments_refactor.cs index a4dc6a2ad..771b58a9b 100644 --- a/BTCPayServer.Data/Migrations/20240317024757_payments_refactor.cs +++ b/BTCPayServer.Data/Migrations/20240317024757_payments_refactor.cs @@ -18,7 +18,7 @@ namespace BTCPayServer.Migrations migrationBuilder.AddColumn( name: "Amount", table: "Payments", - type: migrationBuilder.IsNpgsql() ? "NUMERIC" : "TEXT", + type: "NUMERIC", nullable: true); migrationBuilder.AddColumn( @@ -37,13 +37,11 @@ namespace BTCPayServer.Migrations table: "Payments", type: "TEXT", nullable: true); - if (migrationBuilder.IsNpgsql()) - { - migrationBuilder.AlterColumn( - name: "Accounted", - table: "Payments", - nullable: true); - } + + migrationBuilder.AlterColumn( + name: "Accounted", + table: "Payments", + nullable: true); } /// diff --git a/BTCPayServer.Data/Migrations/20240405052858_cleanup_address_invoices.cs b/BTCPayServer.Data/Migrations/20240405052858_cleanup_address_invoices.cs index 165c1715d..fe645053e 100644 --- a/BTCPayServer.Data/Migrations/20240405052858_cleanup_address_invoices.cs +++ b/BTCPayServer.Data/Migrations/20240405052858_cleanup_address_invoices.cs @@ -15,13 +15,10 @@ namespace BTCPayServer.Migrations /// protected override void Up(MigrationBuilder migrationBuilder) { - if (migrationBuilder.IsNpgsql()) - { - migrationBuilder.Sql(@" + migrationBuilder.Sql(@" DELETE FROM ""AddressInvoices"" WHERE ""Address"" LIKE '%_LightningLike'; ALTER TABLE ""AddressInvoices"" DROP COLUMN IF EXISTS ""CreatedTime""; VACUUM (FULL, ANALYZE) ""AddressInvoices"";", true); - } } /// diff --git a/BTCPayServer/Hosting/MigrationStartupTask.cs b/BTCPayServer/Hosting/MigrationStartupTask.cs index b7a90244f..c6d9c7955 100644 --- a/BTCPayServer/Hosting/MigrationStartupTask.cs +++ b/BTCPayServer/Hosting/MigrationStartupTask.cs @@ -196,12 +196,6 @@ namespace BTCPayServer.Hosting settings.FileSystemStorageAsDefault = true; await _Settings.UpdateSetting(settings); } - if (!settings.FixSeqAfterSqliteMigration) - { - await FixSeqAfterSqliteMigration(); - settings.FixSeqAfterSqliteMigration = true; - await _Settings.UpdateSetting(settings); - } if (!settings.FixMappedDomainAppType) { await FixMappedDomainAppType(); @@ -326,16 +320,6 @@ namespace BTCPayServer.Hosting setting.Value = data.ToString(); await ctx.SaveChangesAsync(); } - - - private async Task FixSeqAfterSqliteMigration() - { - await using var ctx = _DBContextFactory.CreateContext(); - var state = await GetMigrationState(ctx); - if (state != "complete") - return; - await UpdateSequenceInvoiceSearch(ctx); - } static async Task GetMigrationState(ApplicationDbContext postgresContext) { var o = (await postgresContext.Settings.FromSqlRaw("SELECT \"Id\", \"Value\" FROM \"Settings\" WHERE \"Id\"='MigrationData'").AsNoTracking().FirstOrDefaultAsync())?.Value; diff --git a/BTCPayServer/Services/MigrationSettings.cs b/BTCPayServer/Services/MigrationSettings.cs index a787290e2..59b546406 100644 --- a/BTCPayServer/Services/MigrationSettings.cs +++ b/BTCPayServer/Services/MigrationSettings.cs @@ -28,7 +28,6 @@ namespace BTCPayServer.Services public bool MigrateEmailServerDisableTLSCerts { get; set; } public bool MigrateWalletColors { get; set; } public bool FileSystemStorageAsDefault { get; set; } - public bool FixSeqAfterSqliteMigration { get; set; } public bool FixMappedDomainAppType { get; set; } public bool MigrateAppYmlToJson { get; set; } public bool MigrateToStoreConfig { get; set; } diff --git a/BTCPayServer/Services/WalletRepository.cs b/BTCPayServer/Services/WalletRepository.cs index 12ebc487e..e5393d7f9 100644 --- a/BTCPayServer/Services/WalletRepository.cs +++ b/BTCPayServer/Services/WalletRepository.cs @@ -350,17 +350,7 @@ namespace BTCPayServer.Services } private async Task EnsureWalletObjectLinks(ApplicationDbContext ctx, DbConnection connection, IEnumerable links) { - if (!ctx.Database.IsNpgsql()) - { - foreach (var link in links) - { - await EnsureWalletObjectLink(link); - } - } - else - { - await connection.ExecuteAsync("INSERT INTO \"WalletObjectLinks\" VALUES (@WalletId, @AType, @AId, @BType, @BId, @Data::JSONB) ON CONFLICT DO NOTHING", links); - } + await connection.ExecuteAsync("INSERT INTO \"WalletObjectLinks\" VALUES (@WalletId, @AType, @AId, @BType, @BId, @Data::JSONB) ON CONFLICT DO NOTHING", links); } public static WalletObjectLinkData NewWalletObjectLinkData(WalletObjectId a, WalletObjectId b, @@ -380,34 +370,15 @@ namespace BTCPayServer.Services private static async Task UpdateWalletObjectLink(WalletObjectLinkData l, ApplicationDbContext ctx, bool doNothingIfExists) { - if (!ctx.Database.IsNpgsql()) + var connection = ctx.Database.GetDbConnection(); + var conflict = doNothingIfExists ? "ON CONFLICT DO NOTHING" : "ON CONFLICT ON CONSTRAINT \"PK_WalletObjectLinks\" DO UPDATE SET \"Data\"=EXCLUDED.\"Data\""; + try { - var e = ctx.WalletObjectLinks.Add(l); - try - { - await ctx.SaveChangesAsync(); - } - catch (DbUpdateException) // already exists - { - if (!doNothingIfExists) - { - e.State = EntityState.Modified; - await ctx.SaveChangesAsync(); - } - } + await connection.ExecuteAsync("INSERT INTO \"WalletObjectLinks\" VALUES (@WalletId, @AType, @AId, @BType, @BId, @Data::JSONB) " + conflict, l); } - else + catch (PostgresException ex) when (ex.SqlState == PostgresErrorCodes.ForeignKeyViolation) { - var connection = ctx.Database.GetDbConnection(); - var conflict = doNothingIfExists ? "ON CONFLICT DO NOTHING" : "ON CONFLICT ON CONSTRAINT \"PK_WalletObjectLinks\" DO UPDATE SET \"Data\"=EXCLUDED.\"Data\""; - try - { - await connection.ExecuteAsync("INSERT INTO \"WalletObjectLinks\" VALUES (@WalletId, @AType, @AId, @BType, @BId, @Data::JSONB) " + conflict, l); - } - catch (PostgresException ex) when (ex.SqlState == PostgresErrorCodes.ForeignKeyViolation) - { - throw new DbUpdateException(); - } + throw new DbUpdateException(); } } @@ -590,24 +561,8 @@ namespace BTCPayServer.Services ArgumentNullException.ThrowIfNull(id); await using var ctx = _ContextFactory.CreateContext(); var wo = NewWalletObjectData(id, data); - if (!ctx.Database.IsNpgsql()) - { - ctx.WalletObjects.Add(wo); - try - { - await ctx.SaveChangesAsync(); - } - catch (DbUpdateException) // already exists - { - ctx.Entry(wo).State = EntityState.Modified; - await ctx.SaveChangesAsync(); - } - } - else - { - var connection = ctx.Database.GetDbConnection(); - await connection.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT ON CONSTRAINT \"PK_WalletObjects\" DO UPDATE SET \"Data\"=EXCLUDED.\"Data\"", wo); - } + var connection = ctx.Database.GetDbConnection(); + await connection.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT ON CONSTRAINT \"PK_WalletObjects\" DO UPDATE SET \"Data\"=EXCLUDED.\"Data\"", wo); } public async Task EnsureWalletObject(WalletObjectId id, JObject? data = null) @@ -621,41 +576,16 @@ namespace BTCPayServer.Services private async Task EnsureWalletObject(WalletObjectData wo, ApplicationDbContext ctx) { ArgumentNullException.ThrowIfNull(wo); - if (!ctx.Database.IsNpgsql()) - { - var entry = ctx.WalletObjects.Add(wo); - try - { - await ctx.SaveChangesAsync(); - } - catch (DbUpdateException) // already exists - { - entry.State = EntityState.Unchanged; - } - } - else - { - var connection = ctx.Database.GetDbConnection(); - await connection.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT DO NOTHING", wo); - } + var connection = ctx.Database.GetDbConnection(); + await connection.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT DO NOTHING", wo); } private async Task EnsureWalletObjects(ApplicationDbContext ctx,DbConnection connection, IEnumerable data) { var walletObjectDatas = data as WalletObjectData[] ?? data.ToArray(); if(!walletObjectDatas.Any()) - return; - if (!ctx.Database.IsNpgsql()) - { - foreach(var d in walletObjectDatas) - { - await EnsureWalletObject(d, ctx); - } - } - else - { - var conn = ctx.Database.GetDbConnection(); - await conn.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT DO NOTHING", walletObjectDatas); - } + return; + var conn = ctx.Database.GetDbConnection(); + await conn.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT DO NOTHING", walletObjectDatas); } public async Task EnsureCreated(List? walletObjects,