mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-12 10:30:47 +01:00
Remove dead code from multi db support (#5971)
This commit is contained in:
parent
a89c0d4797
commit
8bb4ceaaac
12 changed files with 98 additions and 214 deletions
|
@ -16,8 +16,6 @@ namespace BTCPayServer.Migrations
|
||||||
public partial class WebhookDeliveriesCleanup : Migration
|
public partial class WebhookDeliveriesCleanup : Migration
|
||||||
{
|
{
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
|
||||||
if (migrationBuilder.IsNpgsql())
|
|
||||||
{
|
{
|
||||||
migrationBuilder.Sql("DROP TABLE IF EXISTS \"InvoiceWebhookDeliveries\", \"WebhookDeliveries\";");
|
migrationBuilder.Sql("DROP TABLE IF EXISTS \"InvoiceWebhookDeliveries\", \"WebhookDeliveries\";");
|
||||||
|
|
||||||
|
@ -73,7 +71,6 @@ namespace BTCPayServer.Migrations
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,8 +12,6 @@ namespace BTCPayServer.Migrations
|
||||||
public partial class removecurrentrefund : Migration
|
public partial class removecurrentrefund : Migration
|
||||||
{
|
{
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
|
||||||
if (migrationBuilder.IsNpgsql())
|
|
||||||
{
|
{
|
||||||
migrationBuilder.DropForeignKey(
|
migrationBuilder.DropForeignKey(
|
||||||
name: "FK_Invoices_Refunds_Id_CurrentRefundId",
|
name: "FK_Invoices_Refunds_Id_CurrentRefundId",
|
||||||
|
@ -27,7 +25,6 @@ namespace BTCPayServer.Migrations
|
||||||
name: "CurrentRefundId",
|
name: "CurrentRefundId",
|
||||||
table: "Invoices");
|
table: "Invoices");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,12 +12,9 @@ namespace BTCPayServer.Migrations
|
||||||
public partial class appssettingstojson : Migration
|
public partial class appssettingstojson : Migration
|
||||||
{
|
{
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
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)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,12 +12,9 @@ namespace BTCPayServer.Migrations
|
||||||
public partial class FixWalletObjectsWithEmptyWalletId : Migration
|
public partial class FixWalletObjectsWithEmptyWalletId : Migration
|
||||||
{
|
{
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
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)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,14 +12,11 @@ namespace BTCPayServer.Migrations
|
||||||
public partial class PayoutAndPullPaymentToJsonBlob : Migration
|
public partial class PayoutAndPullPaymentToJsonBlob : Migration
|
||||||
{
|
{
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
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 \"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 \"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 \"PullPayments\" ALTER COLUMN \"Blob\" TYPE JSONB USING regexp_replace(convert_from(\"Blob\",'UTF8'), '\\\\u0000', '', 'g')::JSONB");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
@ -12,24 +12,16 @@ namespace BTCPayServer.Migrations
|
||||||
[Migration("20240229092905_AddManagerAndEmployeeToStoreRoles")]
|
[Migration("20240229092905_AddManagerAndEmployeeToStoreRoles")]
|
||||||
public partial class AddManagerAndEmployeeToStoreRoles : Migration
|
public partial class AddManagerAndEmployeeToStoreRoles : Migration
|
||||||
{
|
{
|
||||||
object GetPermissionsData(MigrationBuilder migrationBuilder, string[] permissions)
|
|
||||||
{
|
|
||||||
return migrationBuilder.IsNpgsql()
|
|
||||||
? permissions
|
|
||||||
: JsonConvert.SerializeObject(permissions);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
var permissionsType = migrationBuilder.IsNpgsql() ? "TEXT[]" : "TEXT";
|
|
||||||
migrationBuilder.InsertData(
|
migrationBuilder.InsertData(
|
||||||
"StoreRoles",
|
"StoreRoles",
|
||||||
columns: new[] { "Id", "Role", "Permissions" },
|
columns: new[] { "Id", "Role", "Permissions" },
|
||||||
columnTypes: new[] { "TEXT", "TEXT", permissionsType },
|
columnTypes: new[] { "TEXT", "TEXT", "TEXT[]" },
|
||||||
values: new object[,]
|
values: new object[,]
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"Manager", "Manager", GetPermissionsData(migrationBuilder, new[]
|
"Manager", "Manager", new[]
|
||||||
{
|
{
|
||||||
"btcpay.store.canviewstoresettings",
|
"btcpay.store.canviewstoresettings",
|
||||||
"btcpay.store.canmodifyinvoices",
|
"btcpay.store.canmodifyinvoices",
|
||||||
|
@ -37,17 +29,17 @@ namespace BTCPayServer.Migrations
|
||||||
"btcpay.store.canmodifypaymentrequests",
|
"btcpay.store.canmodifypaymentrequests",
|
||||||
"btcpay.store.canmanagepullpayments",
|
"btcpay.store.canmanagepullpayments",
|
||||||
"btcpay.store.canmanagepayouts"
|
"btcpay.store.canmanagepayouts"
|
||||||
})
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Employee", "Employee", GetPermissionsData(migrationBuilder, new[]
|
"Employee", "Employee", new[]
|
||||||
{
|
{
|
||||||
"btcpay.store.canmodifyinvoices",
|
"btcpay.store.canmodifyinvoices",
|
||||||
"btcpay.store.canmodifypaymentrequests",
|
"btcpay.store.canmodifypaymentrequests",
|
||||||
"btcpay.store.cancreatenonapprovedpullpayments",
|
"btcpay.store.cancreatenonapprovedpullpayments",
|
||||||
"btcpay.store.canviewpayouts",
|
"btcpay.store.canviewpayouts",
|
||||||
"btcpay.store.canviewpullpayments"
|
"btcpay.store.canviewpullpayments"
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -57,16 +49,16 @@ namespace BTCPayServer.Migrations
|
||||||
keyColumnTypes: new[] { "TEXT" },
|
keyColumnTypes: new[] { "TEXT" },
|
||||||
keyValues: new[] { "Guest" },
|
keyValues: new[] { "Guest" },
|
||||||
columns: new[] { "Permissions" },
|
columns: new[] { "Permissions" },
|
||||||
columnTypes: new[] { permissionsType },
|
columnTypes: new[] { "TEXT[]" },
|
||||||
values: new object[]
|
values: new object[]
|
||||||
{
|
{
|
||||||
GetPermissionsData(migrationBuilder, new[]
|
new[]
|
||||||
{
|
{
|
||||||
"btcpay.store.canmodifyinvoices",
|
"btcpay.store.canmodifyinvoices",
|
||||||
"btcpay.store.canviewpaymentrequests",
|
"btcpay.store.canviewpaymentrequests",
|
||||||
"btcpay.store.canviewpullpayments",
|
"btcpay.store.canviewpullpayments",
|
||||||
"btcpay.store.canviewpayouts"
|
"btcpay.store.canviewpayouts"
|
||||||
})
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,23 +67,22 @@ namespace BTCPayServer.Migrations
|
||||||
migrationBuilder.DeleteData("StoreRoles", "Id", "Manager");
|
migrationBuilder.DeleteData("StoreRoles", "Id", "Manager");
|
||||||
migrationBuilder.DeleteData("StoreRoles", "Id", "Employee");
|
migrationBuilder.DeleteData("StoreRoles", "Id", "Employee");
|
||||||
|
|
||||||
var permissionsType = migrationBuilder.IsNpgsql() ? "TEXT[]" : "TEXT";
|
|
||||||
migrationBuilder.UpdateData(
|
migrationBuilder.UpdateData(
|
||||||
"StoreRoles",
|
"StoreRoles",
|
||||||
keyColumns: new[] { "Id" },
|
keyColumns: new[] { "Id" },
|
||||||
keyColumnTypes: new[] { "TEXT" },
|
keyColumnTypes: new[] { "TEXT" },
|
||||||
keyValues: new[] { "Guest" },
|
keyValues: new[] { "Guest" },
|
||||||
columns: new[] { "Permissions" },
|
columns: new[] { "Permissions" },
|
||||||
columnTypes: new[] { permissionsType },
|
columnTypes: new[] { "TEXT[]" },
|
||||||
values: new object[]
|
values: new object[]
|
||||||
{
|
{
|
||||||
GetPermissionsData(migrationBuilder, new[]
|
new[]
|
||||||
{
|
{
|
||||||
"btcpay.store.canviewstoresettings",
|
"btcpay.store.canviewstoresettings",
|
||||||
"btcpay.store.canmodifyinvoices",
|
"btcpay.store.canmodifyinvoices",
|
||||||
"btcpay.store.canviewcustodianaccounts",
|
"btcpay.store.canviewcustodianaccounts",
|
||||||
"btcpay.store.candeposittocustodianaccount"
|
"btcpay.store.candeposittocustodianaccount"
|
||||||
})
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace BTCPayServer.Migrations
|
||||||
migrationBuilder.AddColumn<decimal>(
|
migrationBuilder.AddColumn<decimal>(
|
||||||
name: "Amount",
|
name: "Amount",
|
||||||
table: "Invoices",
|
table: "Invoices",
|
||||||
type: migrationBuilder.IsNpgsql() ? "NUMERIC" : "TEXT",
|
type: "NUMERIC",
|
||||||
nullable: true);
|
nullable: true);
|
||||||
|
|
||||||
migrationBuilder.AddColumn<string>(
|
migrationBuilder.AddColumn<string>(
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace BTCPayServer.Migrations
|
||||||
migrationBuilder.AddColumn<decimal>(
|
migrationBuilder.AddColumn<decimal>(
|
||||||
name: "Amount",
|
name: "Amount",
|
||||||
table: "Payments",
|
table: "Payments",
|
||||||
type: migrationBuilder.IsNpgsql() ? "NUMERIC" : "TEXT",
|
type: "NUMERIC",
|
||||||
nullable: true);
|
nullable: true);
|
||||||
|
|
||||||
migrationBuilder.AddColumn<DateTimeOffset>(
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||||
|
@ -37,14 +37,12 @@ namespace BTCPayServer.Migrations
|
||||||
table: "Payments",
|
table: "Payments",
|
||||||
type: "TEXT",
|
type: "TEXT",
|
||||||
nullable: true);
|
nullable: true);
|
||||||
if (migrationBuilder.IsNpgsql())
|
|
||||||
{
|
|
||||||
migrationBuilder.AlterColumn<bool?>(
|
migrationBuilder.AlterColumn<bool?>(
|
||||||
name: "Accounted",
|
name: "Accounted",
|
||||||
table: "Payments",
|
table: "Payments",
|
||||||
nullable: true);
|
nullable: true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
|
|
@ -14,15 +14,12 @@ namespace BTCPayServer.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
|
||||||
if (migrationBuilder.IsNpgsql())
|
|
||||||
{
|
{
|
||||||
migrationBuilder.Sql(@"
|
migrationBuilder.Sql(@"
|
||||||
DELETE FROM ""AddressInvoices"" WHERE ""Address"" LIKE '%_LightningLike';
|
DELETE FROM ""AddressInvoices"" WHERE ""Address"" LIKE '%_LightningLike';
|
||||||
ALTER TABLE ""AddressInvoices"" DROP COLUMN IF EXISTS ""CreatedTime"";
|
ALTER TABLE ""AddressInvoices"" DROP COLUMN IF EXISTS ""CreatedTime"";
|
||||||
VACUUM (FULL, ANALYZE) ""AddressInvoices"";", true);
|
VACUUM (FULL, ANALYZE) ""AddressInvoices"";", true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
|
|
@ -196,12 +196,6 @@ namespace BTCPayServer.Hosting
|
||||||
settings.FileSystemStorageAsDefault = true;
|
settings.FileSystemStorageAsDefault = true;
|
||||||
await _Settings.UpdateSetting(settings);
|
await _Settings.UpdateSetting(settings);
|
||||||
}
|
}
|
||||||
if (!settings.FixSeqAfterSqliteMigration)
|
|
||||||
{
|
|
||||||
await FixSeqAfterSqliteMigration();
|
|
||||||
settings.FixSeqAfterSqliteMigration = true;
|
|
||||||
await _Settings.UpdateSetting(settings);
|
|
||||||
}
|
|
||||||
if (!settings.FixMappedDomainAppType)
|
if (!settings.FixMappedDomainAppType)
|
||||||
{
|
{
|
||||||
await FixMappedDomainAppType();
|
await FixMappedDomainAppType();
|
||||||
|
@ -326,16 +320,6 @@ namespace BTCPayServer.Hosting
|
||||||
setting.Value = data.ToString();
|
setting.Value = data.ToString();
|
||||||
await ctx.SaveChangesAsync();
|
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<string> GetMigrationState(ApplicationDbContext postgresContext)
|
static async Task<string> GetMigrationState(ApplicationDbContext postgresContext)
|
||||||
{
|
{
|
||||||
var o = (await postgresContext.Settings.FromSqlRaw("SELECT \"Id\", \"Value\" FROM \"Settings\" WHERE \"Id\"='MigrationData'").AsNoTracking().FirstOrDefaultAsync())?.Value;
|
var o = (await postgresContext.Settings.FromSqlRaw("SELECT \"Id\", \"Value\" FROM \"Settings\" WHERE \"Id\"='MigrationData'").AsNoTracking().FirstOrDefaultAsync())?.Value;
|
||||||
|
|
|
@ -28,7 +28,6 @@ namespace BTCPayServer.Services
|
||||||
public bool MigrateEmailServerDisableTLSCerts { get; set; }
|
public bool MigrateEmailServerDisableTLSCerts { get; set; }
|
||||||
public bool MigrateWalletColors { get; set; }
|
public bool MigrateWalletColors { get; set; }
|
||||||
public bool FileSystemStorageAsDefault { get; set; }
|
public bool FileSystemStorageAsDefault { get; set; }
|
||||||
public bool FixSeqAfterSqliteMigration { get; set; }
|
|
||||||
public bool FixMappedDomainAppType { get; set; }
|
public bool FixMappedDomainAppType { get; set; }
|
||||||
public bool MigrateAppYmlToJson { get; set; }
|
public bool MigrateAppYmlToJson { get; set; }
|
||||||
public bool MigrateToStoreConfig { get; set; }
|
public bool MigrateToStoreConfig { get; set; }
|
||||||
|
|
|
@ -349,19 +349,9 @@ namespace BTCPayServer.Services
|
||||||
|
|
||||||
}
|
}
|
||||||
private async Task EnsureWalletObjectLinks(ApplicationDbContext ctx, DbConnection connection, IEnumerable<WalletObjectLinkData> links)
|
private async Task EnsureWalletObjectLinks(ApplicationDbContext ctx, DbConnection connection, IEnumerable<WalletObjectLinkData> 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,
|
public static WalletObjectLinkData NewWalletObjectLinkData(WalletObjectId a, WalletObjectId b,
|
||||||
JObject? data = null)
|
JObject? data = null)
|
||||||
|
@ -379,24 +369,6 @@ namespace BTCPayServer.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task UpdateWalletObjectLink(WalletObjectLinkData l, ApplicationDbContext ctx, bool doNothingIfExists)
|
private static async Task UpdateWalletObjectLink(WalletObjectLinkData l, ApplicationDbContext ctx, bool doNothingIfExists)
|
||||||
{
|
|
||||||
if (!ctx.Database.IsNpgsql())
|
|
||||||
{
|
|
||||||
var e = ctx.WalletObjectLinks.Add(l);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await ctx.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
catch (DbUpdateException) // already exists
|
|
||||||
{
|
|
||||||
if (!doNothingIfExists)
|
|
||||||
{
|
|
||||||
e.State = EntityState.Modified;
|
|
||||||
await ctx.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
var connection = ctx.Database.GetDbConnection();
|
var connection = ctx.Database.GetDbConnection();
|
||||||
var conflict = doNothingIfExists ? "ON CONFLICT DO NOTHING" : "ON CONFLICT ON CONSTRAINT \"PK_WalletObjectLinks\" DO UPDATE SET \"Data\"=EXCLUDED.\"Data\"";
|
var conflict = doNothingIfExists ? "ON CONFLICT DO NOTHING" : "ON CONFLICT ON CONSTRAINT \"PK_WalletObjectLinks\" DO UPDATE SET \"Data\"=EXCLUDED.\"Data\"";
|
||||||
|
@ -409,7 +381,6 @@ namespace BTCPayServer.Services
|
||||||
throw new DbUpdateException();
|
throw new DbUpdateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class WalletObjectIdComparer : IComparer<WalletObjectId>
|
class WalletObjectIdComparer : IComparer<WalletObjectId>
|
||||||
{
|
{
|
||||||
|
@ -590,25 +561,9 @@ namespace BTCPayServer.Services
|
||||||
ArgumentNullException.ThrowIfNull(id);
|
ArgumentNullException.ThrowIfNull(id);
|
||||||
await using var ctx = _ContextFactory.CreateContext();
|
await using var ctx = _ContextFactory.CreateContext();
|
||||||
var wo = NewWalletObjectData(id, data);
|
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();
|
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);
|
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)
|
public async Task EnsureWalletObject(WalletObjectId id, JObject? data = null)
|
||||||
{
|
{
|
||||||
|
@ -621,42 +576,17 @@ namespace BTCPayServer.Services
|
||||||
private async Task EnsureWalletObject(WalletObjectData wo, ApplicationDbContext ctx)
|
private async Task EnsureWalletObject(WalletObjectData wo, ApplicationDbContext ctx)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(wo);
|
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();
|
var connection = ctx.Database.GetDbConnection();
|
||||||
await connection.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT DO NOTHING", wo);
|
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<WalletObjectData> data)
|
private async Task EnsureWalletObjects(ApplicationDbContext ctx,DbConnection connection, IEnumerable<WalletObjectData> data)
|
||||||
{
|
{
|
||||||
var walletObjectDatas = data as WalletObjectData[] ?? data.ToArray();
|
var walletObjectDatas = data as WalletObjectData[] ?? data.ToArray();
|
||||||
if(!walletObjectDatas.Any())
|
if(!walletObjectDatas.Any())
|
||||||
return;
|
return;
|
||||||
if (!ctx.Database.IsNpgsql())
|
|
||||||
{
|
|
||||||
foreach(var d in walletObjectDatas)
|
|
||||||
{
|
|
||||||
await EnsureWalletObject(d, ctx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var conn = ctx.Database.GetDbConnection();
|
var conn = ctx.Database.GetDbConnection();
|
||||||
await conn.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT DO NOTHING", walletObjectDatas);
|
await conn.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT DO NOTHING", walletObjectDatas);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public async Task EnsureCreated(List<WalletObjectData>? walletObjects,
|
public async Task EnsureCreated(List<WalletObjectData>? walletObjects,
|
||||||
List<WalletObjectLinkData>? walletObjectLinks)
|
List<WalletObjectLinkData>? walletObjectLinks)
|
||||||
|
|
Loading…
Add table
Reference in a new issue