From f4aafd5be3f2b7a306947fd2def353d28f31edee Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Tue, 16 Apr 2024 16:18:56 +0900 Subject: [PATCH] Cleanup AddressesInvoices table (#5905) --- BTCPayServer.Data/Data/AddressInvoiceData.cs | 1 - ...20240405052858_cleanup_address_invoices.cs | 32 +++++++++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 3 -- .../Services/Invoices/InvoiceRepository.cs | 2 -- 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 BTCPayServer.Data/Migrations/20240405052858_cleanup_address_invoices.cs diff --git a/BTCPayServer.Data/Data/AddressInvoiceData.cs b/BTCPayServer.Data/Data/AddressInvoiceData.cs index 00b037650..63e19860d 100644 --- a/BTCPayServer.Data/Data/AddressInvoiceData.cs +++ b/BTCPayServer.Data/Data/AddressInvoiceData.cs @@ -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) diff --git a/BTCPayServer.Data/Migrations/20240405052858_cleanup_address_invoices.cs b/BTCPayServer.Data/Migrations/20240405052858_cleanup_address_invoices.cs new file mode 100644 index 000000000..165c1715d --- /dev/null +++ b/BTCPayServer.Data/Migrations/20240405052858_cleanup_address_invoices.cs @@ -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 + { + /// + 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); + } + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + } + } +} diff --git a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs index bc3a95945..8cc927806 100644 --- a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -63,9 +63,6 @@ namespace BTCPayServer.Migrations b.Property("Address") .HasColumnType("text"); - b.Property("CreatedTime") - .HasColumnType("timestamp with time zone"); - b.Property("InvoiceDataId") .HasColumnType("text"); diff --git a/BTCPayServer/Services/Invoices/InvoiceRepository.cs b/BTCPayServer/Services/Invoices/InvoiceRepository.cs index 9e13b227c..44b5b7590 100644 --- a/BTCPayServer/Services/Invoices/InvoiceRepository.cs +++ b/BTCPayServer/Services/Invoices/InvoiceRepository.cs @@ -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 }); }