Cleanup AddressesInvoices table (#5905)

This commit is contained in:
Nicolas Dorier 2024-04-16 16:18:56 +09:00 committed by GitHub
parent bd978f29a0
commit f4aafd5be3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 6 deletions

View File

@ -9,7 +9,6 @@ namespace BTCPayServer.Data
public string Address { get; set; }
public InvoiceData InvoiceData { get; set; }
public string InvoiceDataId { get; set; }
public DateTimeOffset? CreatedTime { get; set; }
internal static void OnModelCreating(ModelBuilder builder)

View File

@ -0,0 +1,32 @@
using System;
using BTCPayServer.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BTCPayServer.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20240405052858_cleanup_address_invoices")]
public partial class cleanup_address_invoices : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
if (migrationBuilder.IsNpgsql())
{
migrationBuilder.Sql(@"
DELETE FROM ""AddressInvoices"" WHERE ""Address"" LIKE '%_LightningLike';
ALTER TABLE ""AddressInvoices"" DROP COLUMN IF EXISTS ""CreatedTime"";
VACUUM (FULL, ANALYZE) ""AddressInvoices"";", true);
}
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -63,9 +63,6 @@ namespace BTCPayServer.Migrations
b.Property<string>("Address")
.HasColumnType("text");
b.Property<DateTimeOffset?>("CreatedTime")
.HasColumnType("timestamp with time zone");
b.Property<string>("InvoiceDataId")
.HasColumnType("text");

View File

@ -245,7 +245,6 @@ namespace BTCPayServer.Services.Invoices
await context.AddressInvoices.AddAsync(new AddressInvoiceData()
{
InvoiceDataId = invoice.Id,
CreatedTime = DateTimeOffset.UtcNow,
Address = trackedDestination
});
}
@ -363,7 +362,6 @@ retry:
await context.AddressInvoices.AddAsync(new AddressInvoiceData()
{
InvoiceDataId = invoiceId,
CreatedTime = DateTimeOffset.UtcNow,
Address = tracked
});
}