mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-12 02:08:32 +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
|
@ -17,62 +17,59 @@ namespace BTCPayServer.Migrations
|
||||||
{
|
{
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
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\";");
|
Id = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
WebhookId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
migrationBuilder.CreateTable(
|
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
name: "WebhookDeliveries",
|
Pruned = table.Column<bool>(type: "BOOLEAN", nullable: false),
|
||||||
columns: table => new
|
Blob = table.Column<string>(type: "JSONB", nullable: false)
|
||||||
{
|
},
|
||||||
Id = table.Column<string>(type: "TEXT", nullable: false),
|
constraints: table =>
|
||||||
WebhookId = table.Column<string>(type: "TEXT", nullable: false),
|
{
|
||||||
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
table.PrimaryKey("PK_WebhookDeliveries", x => x.Id);
|
||||||
Pruned = table.Column<bool>(type: "BOOLEAN", nullable: false),
|
table.ForeignKey(
|
||||||
Blob = table.Column<string>(type: "JSONB", nullable: false)
|
name: "FK_WebhookDeliveries_Webhooks_WebhookId",
|
||||||
},
|
column: x => x.WebhookId,
|
||||||
constraints: table =>
|
principalTable: "Webhooks",
|
||||||
{
|
principalColumn: "Id",
|
||||||
table.PrimaryKey("PK_WebhookDeliveries", x => x.Id);
|
onDelete: ReferentialAction.Cascade);
|
||||||
table.ForeignKey(
|
});
|
||||||
name: "FK_WebhookDeliveries_Webhooks_WebhookId",
|
|
||||||
column: x => x.WebhookId,
|
|
||||||
principalTable: "Webhooks",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_WebhookDeliveries_WebhookId",
|
name: "IX_WebhookDeliveries_WebhookId",
|
||||||
table: "WebhookDeliveries",
|
table: "WebhookDeliveries",
|
||||||
column: "WebhookId");
|
column: "WebhookId");
|
||||||
migrationBuilder.Sql("CREATE INDEX \"IX_WebhookDeliveries_Timestamp\" ON \"WebhookDeliveries\"(\"Timestamp\") WHERE \"Pruned\" IS FALSE");
|
migrationBuilder.Sql("CREATE INDEX \"IX_WebhookDeliveries_Timestamp\" ON \"WebhookDeliveries\"(\"Timestamp\") WHERE \"Pruned\" IS FALSE");
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "InvoiceWebhookDeliveries",
|
name: "InvoiceWebhookDeliveries",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
InvoiceId = table.Column<string>(type: "TEXT", nullable: false),
|
InvoiceId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
DeliveryId = table.Column<string>(type: "TEXT", nullable: false)
|
DeliveryId = table.Column<string>(type: "TEXT", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_InvoiceWebhookDeliveries", x => new { x.InvoiceId, x.DeliveryId });
|
table.PrimaryKey("PK_InvoiceWebhookDeliveries", x => new { x.InvoiceId, x.DeliveryId });
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_InvoiceWebhookDeliveries_WebhookDeliveries_DeliveryId",
|
name: "FK_InvoiceWebhookDeliveries_WebhookDeliveries_DeliveryId",
|
||||||
column: x => x.DeliveryId,
|
column: x => x.DeliveryId,
|
||||||
principalTable: "WebhookDeliveries",
|
principalTable: "WebhookDeliveries",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_InvoiceWebhookDeliveries_Invoices_InvoiceId",
|
name: "FK_InvoiceWebhookDeliveries_Invoices_InvoiceId",
|
||||||
column: x => x.InvoiceId,
|
column: x => x.InvoiceId,
|
||||||
principalTable: "Invoices",
|
principalTable: "Invoices",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
|
|
@ -13,20 +13,17 @@ namespace BTCPayServer.Migrations
|
||||||
{
|
{
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
if (migrationBuilder.IsNpgsql())
|
migrationBuilder.DropForeignKey(
|
||||||
{
|
name: "FK_Invoices_Refunds_Id_CurrentRefundId",
|
||||||
migrationBuilder.DropForeignKey(
|
table: "Invoices");
|
||||||
name: "FK_Invoices_Refunds_Id_CurrentRefundId",
|
|
||||||
table: "Invoices");
|
|
||||||
|
|
||||||
migrationBuilder.DropIndex(
|
migrationBuilder.DropIndex(
|
||||||
name: "IX_Invoices_Id_CurrentRefundId",
|
name: "IX_Invoices_Id_CurrentRefundId",
|
||||||
table: "Invoices");
|
table: "Invoices");
|
||||||
|
|
||||||
migrationBuilder.DropColumn(
|
migrationBuilder.DropColumn(
|
||||||
name: "CurrentRefundId",
|
name: "CurrentRefundId",
|
||||||
table: "Invoices");
|
table: "Invoices");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
|
|
@ -13,10 +13,7 @@ namespace BTCPayServer.Migrations
|
||||||
{
|
{
|
||||||
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)
|
||||||
|
|
|
@ -13,10 +13,7 @@ namespace BTCPayServer.Migrations
|
||||||
{
|
{
|
||||||
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)
|
||||||
|
|
|
@ -13,12 +13,9 @@ namespace BTCPayServer.Migrations
|
||||||
{
|
{
|
||||||
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 \"Proof\" TYPE JSONB USING regexp_replace(convert_from(\"Proof\",'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 \"PullPayments\" 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)
|
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;
|
||||||
|
@ -11,25 +11,17 @@ namespace BTCPayServer.Migrations
|
||||||
[DbContext(typeof(ApplicationDbContext))]
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
[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,13 +37,11 @@ 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 />
|
||||||
|
|
|
@ -15,13 +15,10 @@ 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 />
|
||||||
|
|
|
@ -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; }
|
||||||
|
|
|
@ -350,17 +350,7 @@ 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())
|
await connection.ExecuteAsync("INSERT INTO \"WalletObjectLinks\" VALUES (@WalletId, @AType, @AId, @BType, @BId, @Data::JSONB) ON CONFLICT DO NOTHING", links);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WalletObjectLinkData NewWalletObjectLinkData(WalletObjectId a, WalletObjectId b,
|
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)
|
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);
|
await connection.ExecuteAsync("INSERT INTO \"WalletObjectLinks\" VALUES (@WalletId, @AType, @AId, @BType, @BId, @Data::JSONB) " + conflict, l);
|
||||||
try
|
|
||||||
{
|
|
||||||
await ctx.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
catch (DbUpdateException) // already exists
|
|
||||||
{
|
|
||||||
if (!doNothingIfExists)
|
|
||||||
{
|
|
||||||
e.State = EntityState.Modified;
|
|
||||||
await ctx.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
catch (PostgresException ex) when (ex.SqlState == PostgresErrorCodes.ForeignKeyViolation)
|
||||||
{
|
{
|
||||||
var connection = ctx.Database.GetDbConnection();
|
throw new DbUpdateException();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,24 +561,8 @@ 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())
|
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);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task EnsureWalletObject(WalletObjectId id, JObject? data = null)
|
public async Task EnsureWalletObject(WalletObjectId id, JObject? data = null)
|
||||||
|
@ -621,41 +576,16 @@ 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 connection = ctx.Database.GetDbConnection();
|
||||||
{
|
await connection.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT DO NOTHING", wo);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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())
|
var conn = ctx.Database.GetDbConnection();
|
||||||
{
|
await conn.ExecuteAsync("INSERT INTO \"WalletObjects\" VALUES (@WalletId, @Type, @Id, @Data::JSONB) ON CONFLICT DO NOTHING", walletObjectDatas);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task EnsureCreated(List<WalletObjectData>? walletObjects,
|
public async Task EnsureCreated(List<WalletObjectData>? walletObjects,
|
||||||
|
|
Loading…
Add table
Reference in a new issue