From f1a04a3bd0861971fcfb1e49a3891d73eaf1505d Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Mon, 15 Apr 2024 19:08:25 +0900 Subject: [PATCH] Remove MySQL and Sqlite deps (#5910) --- .../BTCPayServer.Abstractions.csproj | 2 - .../Contracts/BaseDbContextFactory.cs | 51 +- .../Models/DatabaseOptions.cs | 1 - .../Models/DatabaseType.cs | 9 - BTCPayServer.Data/ApplicationDbContext.cs | 49 +- BTCPayServer.Data/Data/APIKeyData.cs | 9 +- BTCPayServer.Data/Data/AppData.cs | 9 +- BTCPayServer.Data/Data/ApplicationUser.cs | 10 +- BTCPayServer.Data/Data/Fido2Credential.cs | 10 +- BTCPayServer.Data/Data/FormData.cs | 9 +- BTCPayServer.Data/Data/InvoiceData.cs | 15 +- BTCPayServer.Data/Data/LightingAddressData.cs | 9 +- BTCPayServer.Data/Data/NotificationData.cs | 9 +- BTCPayServer.Data/Data/PaymentData.cs | 15 +- BTCPayServer.Data/Data/PaymentRequestData.cs | 9 +- BTCPayServer.Data/Data/PayoutData.cs | 32 +- BTCPayServer.Data/Data/PayoutProcessorData.cs | 9 +- BTCPayServer.Data/Data/PullPaymentData.cs | 19 +- BTCPayServer.Data/Data/SettingData.cs | 9 +- BTCPayServer.Data/Data/StoreData.cs | 25 +- BTCPayServer.Data/Data/StoreRole.cs | 15 - BTCPayServer.Data/Data/StoreSettingData.cs | 10 +- BTCPayServer.Data/Data/WalletObjectData.cs | 10 +- .../Data/WalletObjectLinkData.cs | 9 +- BTCPayServer.Data/Data/WebhookData.cs | 9 +- BTCPayServer.Data/Data/WebhookDeliveryData.cs | 9 +- .../Migrations/20170913143004_Init.cs | 35 +- .../Migrations/20170926073744_Settings.cs | 5 +- ...0170926084408_RequiresEmailConfirmation.cs | 3 +- .../20171006013443_AddressMapping.cs | 7 +- .../Migrations/20171010082424_Tokens.cs | 13 +- .../20171012020112_PendingInvoices.cs | 18 +- .../Migrations/20171023101754_StoreBlob.cs | 3 +- .../20171024163354_RenewUsedAddresses.cs | 5 +- .../20171105235734_PaymentAccounted.cs | 3 +- .../20171221054550_AltcoinSupport.cs | 3 +- .../20180106095215_DerivationStrategies.cs | 3 +- .../20180109021122_defaultcrypto.cs | 3 +- .../Migrations/20180114123253_events.cs | 7 +- .../Migrations/20180402095640_appdata.cs | 7 +- .../Migrations/20180429083930_legacyapikey.cs | 3 +- .../20180719095626_CanDeleteStores.cs | 154 +++--- .../20190121133309_AddPaymentRequests.cs | 7 +- .../Migrations/20190219032533_AppsTagging.cs | 3 +- .../20190225091644_AddOpenIddict.cs | 19 +- .../Migrations/20190324141717_AddFiles.cs | 7 +- .../20190425081749_AddU2fDevices.cs | 25 +- .../20190701082105_sort_paymentrequests.cs | 3 +- .../Migrations/20190802142637_WalletData.cs | 9 +- .../20200110064617_OpenIddictUpdate.cs | 249 ++------- .../20200119130108_ExtendApiKeys.cs | 49 +- .../20200224134444_Remove_OpenIddict.cs | 19 +- .../20200402065615_AddApiKeyBlob.cs | 18 +- .../20200507092343_AddArchivedToInvoice.cs | 15 +- ...25064111_refundnotificationpullpayments.cs | 26 +- ...200901161733_AddInvoiceEventLogSeverity.cs | 10 +- .../20201002145033_AddCreateDateToUser.cs | 10 +- .../20201007090617_u2fDeviceCascade.cs | 46 +- .../20201208054211_invoicesorderindex.cs | 15 +- .../20210314092253_Fido2Credentials.cs | 7 +- .../20220311135252_AddPayoutProcessors.cs | 44 +- .../20220414132313_AddLightningAddress.cs | 7 +- .../20220610090843_AddSettingsToStore.cs | 7 +- .../Migrations/20220929132704_label.cs | 24 +- .../Migrations/20221128062447_jsonb.cs | 7 +- .../20230123062447_migrateoldratesource.cs | 5 +- .../Migrations/20230125085242_AddForms.cs | 9 +- .../Migrations/20230130040047_blob2.cs | 25 +- .../Migrations/20230130062447_jsonb2.cs | 5 +- .../Migrations/20230315062447_fixmaxlength.cs | 7 +- .../Migrations/20230504125505_StoreRoles.cs | 46 +- .../ApplicationDbContextModelSnapshot.cs | 477 +++++++++--------- BTCPayServer.Data/MigrationsExtensions.cs | 28 - BTCPayServer.Tests/FastTests.cs | 11 - BTCPayServer.Tests/GreenfieldAPITests.cs | 21 +- .../Configuration/DefaultConfiguration.cs | 4 - .../GreenField/GreenfieldStoresController.cs | 6 - .../UIStoresController.Settings.cs | 3 +- .../CleanupWebhookDeliveriesTask.cs | 2 - BTCPayServer/Hosting/BTCPayServerServices.cs | 18 +- BTCPayServer/Hosting/MigrationStartupTask.cs | 42 +- .../Hosting/ToPostgresMigrationStartupTask.cs | 296 ----------- .../GeneralSettingsViewModel.cs | 2 - .../Services/Stores/StoreRepository.cs | 25 +- BTCPayServer/Services/WalletRepository.cs | 240 ++++----- .../Views/UIStores/GeneralSettings.cshtml | 5 +- 86 files changed, 818 insertions(+), 1729 deletions(-) delete mode 100644 BTCPayServer.Abstractions/Models/DatabaseType.cs delete mode 100644 BTCPayServer.Data/MigrationsExtensions.cs delete mode 100644 BTCPayServer/Hosting/ToPostgresMigrationStartupTask.cs diff --git a/BTCPayServer.Abstractions/BTCPayServer.Abstractions.csproj b/BTCPayServer.Abstractions/BTCPayServer.Abstractions.csproj index 54a248353..544bab587 100644 --- a/BTCPayServer.Abstractions/BTCPayServer.Abstractions.csproj +++ b/BTCPayServer.Abstractions/BTCPayServer.Abstractions.csproj @@ -33,9 +33,7 @@ - - diff --git a/BTCPayServer.Abstractions/Contracts/BaseDbContextFactory.cs b/BTCPayServer.Abstractions/Contracts/BaseDbContextFactory.cs index 2849a29a5..d5ae67fbf 100644 --- a/BTCPayServer.Abstractions/Contracts/BaseDbContextFactory.cs +++ b/BTCPayServer.Abstractions/Contracts/BaseDbContextFactory.cs @@ -13,12 +13,12 @@ namespace BTCPayServer.Abstractions.Contracts public abstract class BaseDbContextFactory where T : DbContext { private readonly IOptions _options; - private readonly string _schemaPrefix; + private readonly string _migrationTableName; - public BaseDbContextFactory(IOptions options, string schemaPrefix) + public BaseDbContextFactory(IOptions options, string migrationTableName) { _options = options; - _schemaPrefix = schemaPrefix; + _migrationTableName = migrationTableName; } public abstract T CreateContext(); @@ -68,43 +68,16 @@ namespace BTCPayServer.Abstractions.Contracts public void ConfigureBuilder(DbContextOptionsBuilder builder) { - switch (_options.Value.DatabaseType) + builder + .UseNpgsql(_options.Value.ConnectionString, o => { - case DatabaseType.Sqlite: - builder.UseSqlite(_options.Value.ConnectionString, o => - { - if (!string.IsNullOrEmpty(_schemaPrefix)) - { - o.MigrationsHistoryTable(_schemaPrefix); - } - }); - break; - case DatabaseType.Postgres: - builder - .UseNpgsql(_options.Value.ConnectionString, o => - { - o.EnableRetryOnFailure(10); - o.SetPostgresVersion(12, 0); - var mainSearchPath = GetSearchPath(_options.Value.ConnectionString); - var schemaPrefix = string.IsNullOrEmpty(_schemaPrefix) ? "__EFMigrationsHistory" : _schemaPrefix; - o.MigrationsHistoryTable(schemaPrefix, mainSearchPath); - }) - .ReplaceService(); - break; - case DatabaseType.MySQL: - builder.UseMySql(_options.Value.ConnectionString, ServerVersion.AutoDetect(_options.Value.ConnectionString), o => - { - o.EnableRetryOnFailure(10); - - if (!string.IsNullOrEmpty(_schemaPrefix)) - { - o.MigrationsHistoryTable(_schemaPrefix); - } - }); - break; - default: - throw new ArgumentOutOfRangeException(); - } + o.EnableRetryOnFailure(10); + o.SetPostgresVersion(12, 0); + var mainSearchPath = GetSearchPath(_options.Value.ConnectionString); + var schemaPrefix = string.IsNullOrEmpty(_migrationTableName) ? "__EFMigrationsHistory" : _migrationTableName; + o.MigrationsHistoryTable(schemaPrefix, mainSearchPath); + }) + .ReplaceService(); } private string GetSearchPath(string connectionString) diff --git a/BTCPayServer.Abstractions/Models/DatabaseOptions.cs b/BTCPayServer.Abstractions/Models/DatabaseOptions.cs index b4a3f8801..bc2e3d885 100644 --- a/BTCPayServer.Abstractions/Models/DatabaseOptions.cs +++ b/BTCPayServer.Abstractions/Models/DatabaseOptions.cs @@ -2,7 +2,6 @@ namespace BTCPayServer.Abstractions.Models { public class DatabaseOptions { - public DatabaseType DatabaseType { get; set; } public string ConnectionString { get; set; } } } diff --git a/BTCPayServer.Abstractions/Models/DatabaseType.cs b/BTCPayServer.Abstractions/Models/DatabaseType.cs deleted file mode 100644 index 09347b2e1..000000000 --- a/BTCPayServer.Abstractions/Models/DatabaseType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace BTCPayServer.Abstractions.Models -{ - public enum DatabaseType - { - Sqlite, - Postgres, - MySQL, - } -} diff --git a/BTCPayServer.Data/ApplicationDbContext.cs b/BTCPayServer.Data/ApplicationDbContext.cs index bc60fa9dd..2614cfc94 100644 --- a/BTCPayServer.Data/ApplicationDbContext.cs +++ b/BTCPayServer.Data/ApplicationDbContext.cs @@ -12,30 +12,18 @@ namespace BTCPayServer.Data { public ApplicationDbContext CreateDbContext(string[] args) { - var builder = new DbContextOptionsBuilder(); - - builder.UseSqlite("Data Source=temp.db"); - - return new ApplicationDbContext(builder.Options, true); + // Same as launchsettings.json, it's connecting to the docker's postgres. + builder.UseNpgsql("User ID=postgres;Include Error Detail=true;Host=127.0.0.1;Port=39372;Database=btcpayserver"); + return new ApplicationDbContext(builder.Options); } } - public class ApplicationDbContext : IdentityDbContext { - private readonly bool _designTime; - - public ApplicationDbContext(DbContextOptions options, bool designTime = false) + public ApplicationDbContext(DbContextOptions options) : base(options) { - _designTime = designTime; } -#nullable enable - public async Task GetMigrationState() - { - return (await Settings.FromSqlRaw("SELECT \"Id\", \"Value\" FROM \"Settings\" WHERE \"Id\"='MigrationData'").AsNoTracking().FirstOrDefaultAsync())?.Value; - } -#nullable restore public DbSet AddressInvoices { get; set; } public DbSet ApiKeys { get; set; } public DbSet Apps { get; set; } @@ -76,13 +64,6 @@ namespace BTCPayServer.Data public DbSet PayoutProcessors { get; set; } public DbSet Forms { get; set; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - var isConfigured = optionsBuilder.Options.Extensions.OfType().Any(); - if (!isConfigured) - optionsBuilder.UseSqlite("Data Source=temp.db"); - } - protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); @@ -129,28 +110,6 @@ namespace BTCPayServer.Data WebhookData.OnModelCreating(builder, Database); FormData.OnModelCreating(builder, Database); StoreRole.OnModelCreating(builder, Database); - - - if (Database.IsSqlite() && !_designTime) - { - // SQLite does not have proper support for DateTimeOffset via Entity Framework Core, see the limitations - // here: https://docs.microsoft.com/en-us/ef/core/providers/sqlite/limitations#query-limitations - // To work around this, when the Sqlite database provider is used, all model properties of type DateTimeOffset - // use the DateTimeOffsetToBinaryConverter - // Based on: https://github.com/aspnet/EntityFrameworkCore/issues/10784#issuecomment-415769754 - // This only supports millisecond precision, but should be sufficient for most use cases. - foreach (var entityType in builder.Model.GetEntityTypes()) - { - var properties = entityType.ClrType.GetProperties().Where(p => p.PropertyType == typeof(DateTimeOffset)); - foreach (var property in properties) - { - builder - .Entity(entityType.Name) - .Property(property.Name) - .HasConversion(new Microsoft.EntityFrameworkCore.Storage.ValueConversion.DateTimeOffsetToBinaryConverter()); - } - } - } } } diff --git a/BTCPayServer.Data/Data/APIKeyData.cs b/BTCPayServer.Data/Data/APIKeyData.cs index e0de051fa..48e2d6972 100644 --- a/BTCPayServer.Data/Data/APIKeyData.cs +++ b/BTCPayServer.Data/Data/APIKeyData.cs @@ -41,12 +41,9 @@ namespace BTCPayServer.Data builder.Entity() .HasIndex(o => o.StoreId); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob2) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Blob2) + .HasColumnType("JSONB"); } } diff --git a/BTCPayServer.Data/Data/AppData.cs b/BTCPayServer.Data/Data/AppData.cs index 784f9162c..c2de73233 100644 --- a/BTCPayServer.Data/Data/AppData.cs +++ b/BTCPayServer.Data/Data/AppData.cs @@ -25,12 +25,9 @@ namespace BTCPayServer.Data builder.Entity() .HasOne(a => a.StoreData); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Settings) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Settings) + .HasColumnType("JSONB"); } // utility methods diff --git a/BTCPayServer.Data/Data/ApplicationUser.cs b/BTCPayServer.Data/Data/ApplicationUser.cs index 3cb2972fb..f0c59c6dd 100644 --- a/BTCPayServer.Data/Data/ApplicationUser.cs +++ b/BTCPayServer.Data/Data/ApplicationUser.cs @@ -35,12 +35,10 @@ namespace BTCPayServer.Data builder.Entity() .HasMany>(user => user.UserRoles) .WithOne().HasForeignKey(role => role.UserId); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob2) - .HasColumnType("JSONB"); - } + + builder.Entity() + .Property(o => o.Blob2) + .HasColumnType("JSONB"); } } diff --git a/BTCPayServer.Data/Data/Fido2Credential.cs b/BTCPayServer.Data/Data/Fido2Credential.cs index 6aeb5af26..086925710 100644 --- a/BTCPayServer.Data/Data/Fido2Credential.cs +++ b/BTCPayServer.Data/Data/Fido2Credential.cs @@ -30,12 +30,10 @@ namespace BTCPayServer.Data .HasOne(o => o.ApplicationUser) .WithMany(i => i.Fido2Credentials) .HasForeignKey(i => i.ApplicationUserId).OnDelete(DeleteBehavior.Cascade); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob2) - .HasColumnType("JSONB"); - } + + builder.Entity() + .Property(o => o.Blob2) + .HasColumnType("JSONB"); } public ApplicationUser ApplicationUser { get; set; } diff --git a/BTCPayServer.Data/Data/FormData.cs b/BTCPayServer.Data/Data/FormData.cs index 7519f10bf..2c8df6c96 100644 --- a/BTCPayServer.Data/Data/FormData.cs +++ b/BTCPayServer.Data/Data/FormData.cs @@ -21,11 +21,8 @@ public class FormData .WithMany(o => o.Forms).OnDelete(DeleteBehavior.Cascade); builder.Entity().HasIndex(o => o.StoreId); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Config) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Config) + .HasColumnType("JSONB"); } } diff --git a/BTCPayServer.Data/Data/InvoiceData.cs b/BTCPayServer.Data/Data/InvoiceData.cs index 6bdbe5028..80092d02d 100644 --- a/BTCPayServer.Data/Data/InvoiceData.cs +++ b/BTCPayServer.Data/Data/InvoiceData.cs @@ -44,15 +44,12 @@ namespace BTCPayServer.Data builder.Entity().HasIndex(o => o.StoreDataId); builder.Entity().HasIndex(o => o.OrderId); builder.Entity().HasIndex(o => o.Created); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob2) - .HasColumnType("JSONB"); - builder.Entity() - .Property(o => o.Amount) - .HasColumnType("NUMERIC"); - } + builder.Entity() + .Property(o => o.Blob2) + .HasColumnType("JSONB"); + builder.Entity() + .Property(o => o.Amount) + .HasColumnType("NUMERIC"); } } } diff --git a/BTCPayServer.Data/Data/LightingAddressData.cs b/BTCPayServer.Data/Data/LightingAddressData.cs index f5115c02d..e12753f67 100644 --- a/BTCPayServer.Data/Data/LightingAddressData.cs +++ b/BTCPayServer.Data/Data/LightingAddressData.cs @@ -27,12 +27,9 @@ public class LightningAddressData : IHasBlob .IsRequired() .OnDelete(DeleteBehavior.Cascade); builder.Entity().HasKey(o => o.Username); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob2) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Blob2) + .HasColumnType("JSONB"); } } diff --git a/BTCPayServer.Data/Data/NotificationData.cs b/BTCPayServer.Data/Data/NotificationData.cs index 847ccd56f..3e099980f 100644 --- a/BTCPayServer.Data/Data/NotificationData.cs +++ b/BTCPayServer.Data/Data/NotificationData.cs @@ -30,12 +30,9 @@ namespace BTCPayServer.Data .HasOne(o => o.ApplicationUser) .WithMany(n => n.Notifications) .HasForeignKey(k => k.ApplicationUserId).OnDelete(DeleteBehavior.Cascade); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob2) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Blob2) + .HasColumnType("JSONB"); } } } diff --git a/BTCPayServer.Data/Data/PaymentData.cs b/BTCPayServer.Data/Data/PaymentData.cs index 4758d9ecb..52233b417 100644 --- a/BTCPayServer.Data/Data/PaymentData.cs +++ b/BTCPayServer.Data/Data/PaymentData.cs @@ -41,15 +41,12 @@ namespace BTCPayServer.Data builder.Entity() .Property(o => o.Status) .HasConversion(); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob2) - .HasColumnType("JSONB"); - builder.Entity() - .Property(o => o.Amount) - .HasColumnType("NUMERIC"); - } + builder.Entity() + .Property(o => o.Blob2) + .HasColumnType("JSONB"); + builder.Entity() + .Property(o => o.Amount) + .HasColumnType("NUMERIC"); } } } diff --git a/BTCPayServer.Data/Data/PaymentRequestData.cs b/BTCPayServer.Data/Data/PaymentRequestData.cs index cb96ced46..4abf3846d 100644 --- a/BTCPayServer.Data/Data/PaymentRequestData.cs +++ b/BTCPayServer.Data/Data/PaymentRequestData.cs @@ -32,12 +32,9 @@ namespace BTCPayServer.Data builder.Entity() .HasIndex(o => o.Status); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob2) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Blob2) + .HasColumnType("JSONB"); } } } diff --git a/BTCPayServer.Data/Data/PayoutData.cs b/BTCPayServer.Data/Data/PayoutData.cs index 6f5533cf7..c1cd5b87a 100644 --- a/BTCPayServer.Data/Data/PayoutData.cs +++ b/BTCPayServer.Data/Data/PayoutData.cs @@ -47,32 +47,12 @@ namespace BTCPayServer.Data builder.Entity() .HasIndex(x => new { DestinationId = x.Destination, x.State }); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob) - .HasColumnType("JSONB"); - builder.Entity() - .Property(o => o.Proof) - .HasColumnType("JSONB"); - } - else if (databaseFacade.IsMySql()) - { - builder.Entity() - .Property(o => o.Blob) - .HasConversion(new ValueConverter - ( - convertToProviderExpression: (str) => Encoding.UTF8.GetBytes(str), - convertFromProviderExpression: (bytes) => Encoding.UTF8.GetString(bytes) - )); - builder.Entity() - .Property(o => o.Proof) - .HasConversion(new ValueConverter - ( - convertToProviderExpression: (str) => Encoding.UTF8.GetBytes(str), - convertFromProviderExpression: (bytes) => Encoding.UTF8.GetString(bytes) - )); - } + builder.Entity() + .Property(o => o.Blob) + .HasColumnType("JSONB"); + builder.Entity() + .Property(o => o.Proof) + .HasColumnType("JSONB"); } // utility methods diff --git a/BTCPayServer.Data/Data/PayoutProcessorData.cs b/BTCPayServer.Data/Data/PayoutProcessorData.cs index 2ac197a9f..c56e93899 100644 --- a/BTCPayServer.Data/Data/PayoutProcessorData.cs +++ b/BTCPayServer.Data/Data/PayoutProcessorData.cs @@ -29,12 +29,9 @@ public class PayoutProcessorData : IHasBlobUntyped .HasOne(o => o.Store) .WithMany(data => data.PayoutProcessors).OnDelete(DeleteBehavior.Cascade); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob2) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Blob2) + .HasColumnType("JSONB"); } public override string ToString() diff --git a/BTCPayServer.Data/Data/PullPaymentData.cs b/BTCPayServer.Data/Data/PullPaymentData.cs index d78355f75..66abd7702 100644 --- a/BTCPayServer.Data/Data/PullPaymentData.cs +++ b/BTCPayServer.Data/Data/PullPaymentData.cs @@ -38,22 +38,9 @@ namespace BTCPayServer.Data .HasOne(o => o.StoreData) .WithMany(o => o.PullPayments).OnDelete(DeleteBehavior.Cascade); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob) - .HasColumnType("JSONB"); - } - else if (databaseFacade.IsMySql()) - { - builder.Entity() - .Property(o => o.Blob) - .HasConversion(new ValueConverter - ( - convertToProviderExpression: (str) => Encoding.UTF8.GetBytes(str), - convertFromProviderExpression: (bytes) => Encoding.UTF8.GetString(bytes) - )); - } + builder.Entity() + .Property(o => o.Blob) + .HasColumnType("JSONB"); } public (DateTimeOffset Start, DateTimeOffset? End)? GetPeriod(DateTimeOffset now) diff --git a/BTCPayServer.Data/Data/SettingData.cs b/BTCPayServer.Data/Data/SettingData.cs index fefec2f65..6d17107d7 100644 --- a/BTCPayServer.Data/Data/SettingData.cs +++ b/BTCPayServer.Data/Data/SettingData.cs @@ -11,12 +11,9 @@ namespace BTCPayServer.Data public static void OnModelCreating(ModelBuilder builder, DatabaseFacade databaseFacade) { - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Value) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Value) + .HasColumnType("JSONB"); } } } diff --git a/BTCPayServer.Data/Data/StoreData.cs b/BTCPayServer.Data/Data/StoreData.cs index ac2b1d0cb..d42e14d6d 100644 --- a/BTCPayServer.Data/Data/StoreData.cs +++ b/BTCPayServer.Data/Data/StoreData.cs @@ -52,26 +52,13 @@ namespace BTCPayServer.Data internal static void OnModelCreating(ModelBuilder builder, DatabaseFacade databaseFacade) { - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.StoreBlob) - .HasColumnType("JSONB"); + builder.Entity() + .Property(o => o.StoreBlob) + .HasColumnType("JSONB"); - builder.Entity() - .Property(o => o.DerivationStrategies) - .HasColumnType("JSONB"); - } - else if (databaseFacade.IsMySql()) - { - builder.Entity() - .Property(o => o.StoreBlob) - .HasConversion(new ValueConverter - ( - convertToProviderExpression: (str) => Encoding.UTF8.GetBytes(str), - convertFromProviderExpression: (bytes) => Encoding.UTF8.GetString(bytes) - )); - } + builder.Entity() + .Property(o => o.DerivationStrategies) + .HasColumnType("JSONB"); } } } diff --git a/BTCPayServer.Data/Data/StoreRole.cs b/BTCPayServer.Data/Data/StoreRole.cs index 78de92879..b872300eb 100644 --- a/BTCPayServer.Data/Data/StoreRole.cs +++ b/BTCPayServer.Data/Data/StoreRole.cs @@ -31,20 +31,5 @@ public class StoreRole entity.HasIndex(entity => new {entity.StoreDataId, entity.Role}).IsUnique(); }); - - - - if (!databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Permissions) - .HasConversion( - v => JsonConvert.SerializeObject(v), - v => JsonConvert.DeserializeObject>(v)?? new List(), - new ValueComparer>( - (c1, c2) => c1 ==c2 || c1 != null && c2 != null && c1.SequenceEqual(c2), - c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())), - c => c.ToList())); - } } } diff --git a/BTCPayServer.Data/Data/StoreSettingData.cs b/BTCPayServer.Data/Data/StoreSettingData.cs index aa89588d7..88319f33c 100644 --- a/BTCPayServer.Data/Data/StoreSettingData.cs +++ b/BTCPayServer.Data/Data/StoreSettingData.cs @@ -18,11 +18,9 @@ public class StoreSettingData builder.Entity() .HasOne(o => o.Store) .WithMany(o => o.Settings).OnDelete(DeleteBehavior.Cascade); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Value) - .HasColumnType("JSONB"); - } + + builder.Entity() + .Property(o => o.Value) + .HasColumnType("JSONB"); } } diff --git a/BTCPayServer.Data/Data/WalletObjectData.cs b/BTCPayServer.Data/Data/WalletObjectData.cs index 15b514dda..7d6c304a6 100644 --- a/BTCPayServer.Data/Data/WalletObjectData.cs +++ b/BTCPayServer.Data/Data/WalletObjectData.cs @@ -83,13 +83,9 @@ namespace BTCPayServer.Data o.Id }); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Data) - .HasColumnType("JSONB"); - - } + builder.Entity() + .Property(o => o.Data) + .HasColumnType("JSONB"); } public bool Equals(WalletObjectData x, WalletObjectData y) diff --git a/BTCPayServer.Data/Data/WalletObjectLinkData.cs b/BTCPayServer.Data/Data/WalletObjectLinkData.cs index 9393c4589..5c4dae137 100644 --- a/BTCPayServer.Data/Data/WalletObjectLinkData.cs +++ b/BTCPayServer.Data/Data/WalletObjectLinkData.cs @@ -50,12 +50,9 @@ namespace BTCPayServer.Data .HasForeignKey(o => new { o.WalletId, o.BType, o.BId }) .OnDelete(DeleteBehavior.Cascade); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Data) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Data) + .HasColumnType("JSONB"); } } } diff --git a/BTCPayServer.Data/Data/WebhookData.cs b/BTCPayServer.Data/Data/WebhookData.cs index c251cf4b8..c2655f3df 100644 --- a/BTCPayServer.Data/Data/WebhookData.cs +++ b/BTCPayServer.Data/Data/WebhookData.cs @@ -18,12 +18,9 @@ namespace BTCPayServer.Data internal static void OnModelCreating(ModelBuilder builder, DatabaseFacade databaseFacade) { - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob2) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Blob2) + .HasColumnType("JSONB"); } } } diff --git a/BTCPayServer.Data/Data/WebhookDeliveryData.cs b/BTCPayServer.Data/Data/WebhookDeliveryData.cs index 53ecbdb5b..977834f9d 100644 --- a/BTCPayServer.Data/Data/WebhookDeliveryData.cs +++ b/BTCPayServer.Data/Data/WebhookDeliveryData.cs @@ -27,12 +27,9 @@ namespace BTCPayServer.Data .WithMany(a => a.Deliveries).OnDelete(DeleteBehavior.Cascade); builder.Entity().HasIndex(o => o.WebhookId); builder.Entity().HasIndex(o => o.Timestamp); - if (databaseFacade.IsNpgsql()) - { - builder.Entity() - .Property(o => o.Blob) - .HasColumnType("JSONB"); - } + builder.Entity() + .Property(o => o.Blob) + .HasColumnType("JSONB"); } } } diff --git a/BTCPayServer.Data/Migrations/20170913143004_Init.cs b/BTCPayServer.Data/Migrations/20170913143004_Init.cs index 70707fc2a..36736869c 100644 --- a/BTCPayServer.Data/Migrations/20170913143004_Init.cs +++ b/BTCPayServer.Data/Migrations/20170913143004_Init.cs @@ -11,12 +11,11 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; migrationBuilder.CreateTable( name: "AspNetRoles", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), ConcurrencyStamp = table.Column(nullable: true), Name = table.Column(maxLength: 256, nullable: true), NormalizedName = table.Column(maxLength: 256, nullable: true) @@ -30,7 +29,7 @@ namespace BTCPayServer.Migrations name: "AspNetUsers", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), AccessFailedCount = table.Column(nullable: false), ConcurrencyStamp = table.Column(nullable: true), Email = table.Column(maxLength: 256, nullable: true), @@ -55,7 +54,7 @@ namespace BTCPayServer.Migrations name: "Stores", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), DerivationStrategy = table.Column(nullable: true), SpeedPolicy = table.Column(nullable: false), StoreCertificate = table.Column(nullable: true), @@ -75,7 +74,7 @@ namespace BTCPayServer.Migrations .Annotation("Sqlite:Autoincrement", true), ClaimType = table.Column(nullable: true), ClaimValue = table.Column(nullable: true), - RoleId = table.Column(nullable: false, maxLength: maxLength) + RoleId = table.Column(nullable: false, maxLength: null) }, constraints: table => { @@ -96,7 +95,7 @@ namespace BTCPayServer.Migrations .Annotation("Sqlite:Autoincrement", true), ClaimType = table.Column(nullable: true), ClaimValue = table.Column(nullable: true), - UserId = table.Column(nullable: false, maxLength: maxLength) + UserId = table.Column(nullable: false, maxLength: null) }, constraints: table => { @@ -116,7 +115,7 @@ namespace BTCPayServer.Migrations LoginProvider = table.Column(nullable: false, maxLength: 255), ProviderKey = table.Column(nullable: false, maxLength: 255), ProviderDisplayName = table.Column(nullable: true), - UserId = table.Column(nullable: false, maxLength: maxLength) + UserId = table.Column(nullable: false, maxLength: null) }, constraints: table => { @@ -133,8 +132,8 @@ namespace BTCPayServer.Migrations name: "AspNetUserRoles", columns: table => new { - UserId = table.Column(nullable: false, maxLength: maxLength), - RoleId = table.Column(nullable: false, maxLength: maxLength) + UserId = table.Column(nullable: false, maxLength: null), + RoleId = table.Column(nullable: false, maxLength: null) }, constraints: table => { @@ -157,7 +156,7 @@ namespace BTCPayServer.Migrations name: "AspNetUserTokens", columns: table => new { - UserId = table.Column(nullable: false, maxLength: maxLength), + UserId = table.Column(nullable: false, maxLength: null), LoginProvider = table.Column(nullable: false, maxLength: 64), Name = table.Column(nullable: false, maxLength: 64), Value = table.Column(nullable: true) @@ -177,7 +176,7 @@ namespace BTCPayServer.Migrations name: "Invoices", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Blob = table.Column(nullable: true), Created = table.Column(nullable: false), CustomerEmail = table.Column(nullable: true), @@ -185,7 +184,7 @@ namespace BTCPayServer.Migrations ItemCode = table.Column(nullable: true), OrderId = table.Column(nullable: true), Status = table.Column(nullable: true), - StoreDataId = table.Column(nullable: true, maxLength: maxLength) + StoreDataId = table.Column(nullable: true, maxLength: null) }, constraints: table => { @@ -202,8 +201,8 @@ namespace BTCPayServer.Migrations name: "UserStore", columns: table => new { - ApplicationUserId = table.Column(nullable: false, maxLength: maxLength), - StoreDataId = table.Column(nullable: false, maxLength: maxLength), + ApplicationUserId = table.Column(nullable: false, maxLength: null), + StoreDataId = table.Column(nullable: false, maxLength: null), Role = table.Column(nullable: true) }, constraints: table => @@ -227,9 +226,9 @@ namespace BTCPayServer.Migrations name: "Payments", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Blob = table.Column(nullable: true), - InvoiceDataId = table.Column(nullable: true, maxLength: maxLength) + InvoiceDataId = table.Column(nullable: true, maxLength: null) }, constraints: table => { @@ -246,9 +245,9 @@ namespace BTCPayServer.Migrations name: "RefundAddresses", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Blob = table.Column(nullable: true), - InvoiceDataId = table.Column(nullable: true, maxLength: maxLength) + InvoiceDataId = table.Column(nullable: true, maxLength: null) }, constraints: table => { diff --git a/BTCPayServer.Data/Migrations/20170926073744_Settings.cs b/BTCPayServer.Data/Migrations/20170926073744_Settings.cs index 488e0d820..67ea47fda 100644 --- a/BTCPayServer.Data/Migrations/20170926073744_Settings.cs +++ b/BTCPayServer.Data/Migrations/20170926073744_Settings.cs @@ -10,12 +10,11 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "Settings", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Value = table.Column(nullable: true) }, constraints: table => diff --git a/BTCPayServer.Data/Migrations/20170926084408_RequiresEmailConfirmation.cs b/BTCPayServer.Data/Migrations/20170926084408_RequiresEmailConfirmation.cs index 9a123c0c0..d1e7bc831 100644 --- a/BTCPayServer.Data/Migrations/20170926084408_RequiresEmailConfirmation.cs +++ b/BTCPayServer.Data/Migrations/20170926084408_RequiresEmailConfirmation.cs @@ -10,8 +10,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.AddColumn( + migrationBuilder.AddColumn( name: "RequiresEmailConfirmation", table: "AspNetUsers", nullable: false, diff --git a/BTCPayServer.Data/Migrations/20171006013443_AddressMapping.cs b/BTCPayServer.Data/Migrations/20171006013443_AddressMapping.cs index 756be1e29..011ff100d 100644 --- a/BTCPayServer.Data/Migrations/20171006013443_AddressMapping.cs +++ b/BTCPayServer.Data/Migrations/20171006013443_AddressMapping.cs @@ -10,13 +10,12 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "AddressInvoices", columns: table => new { - Address = table.Column(nullable: false, maxLength: this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)512 : null), - InvoiceDataId = table.Column(nullable: true, maxLength: maxLength) + Address = table.Column(nullable: false, maxLength: null), + InvoiceDataId = table.Column(nullable: true, maxLength: null) }, constraints: table => { diff --git a/BTCPayServer.Data/Migrations/20171010082424_Tokens.cs b/BTCPayServer.Data/Migrations/20171010082424_Tokens.cs index 2bb7f08ad..1846dbdb1 100644 --- a/BTCPayServer.Data/Migrations/20171010082424_Tokens.cs +++ b/BTCPayServer.Data/Migrations/20171010082424_Tokens.cs @@ -11,18 +11,17 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "PairedSINData", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Facade = table.Column(nullable: true), Label = table.Column(nullable: true), Name = table.Column(nullable: true), PairingTime = table.Column(nullable: false), - SIN = table.Column(nullable: true, maxLength: maxLength), - StoreDataId = table.Column(nullable: true, maxLength: maxLength) + SIN = table.Column(nullable: true, maxLength: null), + StoreDataId = table.Column(nullable: true, maxLength: null) }, constraints: table => { @@ -33,14 +32,14 @@ namespace BTCPayServer.Migrations name: "PairingCodes", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), DateCreated = table.Column(nullable: false), Expiration = table.Column(nullable: false), Facade = table.Column(nullable: true), Label = table.Column(nullable: true), Name = table.Column(nullable: true), SIN = table.Column(nullable: true), - StoreDataId = table.Column(nullable: true, maxLength: maxLength), + StoreDataId = table.Column(nullable: true, maxLength: null), TokenValue = table.Column(nullable: true) }, constraints: table => diff --git a/BTCPayServer.Data/Migrations/20171012020112_PendingInvoices.cs b/BTCPayServer.Data/Migrations/20171012020112_PendingInvoices.cs index 5ed483217..57bbfc964 100644 --- a/BTCPayServer.Data/Migrations/20171012020112_PendingInvoices.cs +++ b/BTCPayServer.Data/Migrations/20171012020112_PendingInvoices.cs @@ -10,22 +10,18 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - if (this.SupportDropColumn(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropColumn( - name: "Name", - table: "PairingCodes"); + migrationBuilder.DropColumn( + name: "Name", + table: "PairingCodes"); - migrationBuilder.DropColumn( - name: "Name", - table: "PairedSINData"); - } + migrationBuilder.DropColumn( + name: "Name", + table: "PairedSINData"); migrationBuilder.CreateTable( name: "PendingInvoices", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength) + Id = table.Column(nullable: false, maxLength: null) }, constraints: table => { diff --git a/BTCPayServer.Data/Migrations/20171023101754_StoreBlob.cs b/BTCPayServer.Data/Migrations/20171023101754_StoreBlob.cs index 67e5543fe..deec42c08 100644 --- a/BTCPayServer.Data/Migrations/20171023101754_StoreBlob.cs +++ b/BTCPayServer.Data/Migrations/20171023101754_StoreBlob.cs @@ -10,8 +10,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.AddColumn( + migrationBuilder.AddColumn( name: "StoreBlob", table: "Stores", nullable: true); diff --git a/BTCPayServer.Data/Migrations/20171024163354_RenewUsedAddresses.cs b/BTCPayServer.Data/Migrations/20171024163354_RenewUsedAddresses.cs index 9a50572f6..eb222a16d 100644 --- a/BTCPayServer.Data/Migrations/20171024163354_RenewUsedAddresses.cs +++ b/BTCPayServer.Data/Migrations/20171024163354_RenewUsedAddresses.cs @@ -11,7 +11,6 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; migrationBuilder.AddColumn( name: "CreatedTime", table: "AddressInvoices", @@ -21,8 +20,8 @@ namespace BTCPayServer.Migrations name: "HistoricalAddressInvoices", columns: table => new { - InvoiceDataId = table.Column(nullable: false, maxLength: maxLength), - Address = table.Column(nullable: false, maxLength: this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)512 : null), + InvoiceDataId = table.Column(nullable: false, maxLength: null), + Address = table.Column(nullable: false, maxLength: null), Assigned = table.Column(nullable: false), UnAssigned = table.Column(nullable: true) }, diff --git a/BTCPayServer.Data/Migrations/20171105235734_PaymentAccounted.cs b/BTCPayServer.Data/Migrations/20171105235734_PaymentAccounted.cs index 04445b8e4..c0e3f02c2 100644 --- a/BTCPayServer.Data/Migrations/20171105235734_PaymentAccounted.cs +++ b/BTCPayServer.Data/Migrations/20171105235734_PaymentAccounted.cs @@ -10,8 +10,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.AddColumn( + migrationBuilder.AddColumn( name: "Accounted", table: "Payments", nullable: false, diff --git a/BTCPayServer.Data/Migrations/20171221054550_AltcoinSupport.cs b/BTCPayServer.Data/Migrations/20171221054550_AltcoinSupport.cs index ba670f25b..b07ecf638 100644 --- a/BTCPayServer.Data/Migrations/20171221054550_AltcoinSupport.cs +++ b/BTCPayServer.Data/Migrations/20171221054550_AltcoinSupport.cs @@ -10,8 +10,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.AddColumn( + migrationBuilder.AddColumn( name: "CryptoCode", table: "HistoricalAddressInvoices", nullable: true); diff --git a/BTCPayServer.Data/Migrations/20180106095215_DerivationStrategies.cs b/BTCPayServer.Data/Migrations/20180106095215_DerivationStrategies.cs index 692486b10..ed760fe52 100644 --- a/BTCPayServer.Data/Migrations/20180106095215_DerivationStrategies.cs +++ b/BTCPayServer.Data/Migrations/20180106095215_DerivationStrategies.cs @@ -10,8 +10,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.AddColumn( + migrationBuilder.AddColumn( name: "DerivationStrategies", table: "Stores", nullable: true); diff --git a/BTCPayServer.Data/Migrations/20180109021122_defaultcrypto.cs b/BTCPayServer.Data/Migrations/20180109021122_defaultcrypto.cs index 9a1819f1a..393526634 100644 --- a/BTCPayServer.Data/Migrations/20180109021122_defaultcrypto.cs +++ b/BTCPayServer.Data/Migrations/20180109021122_defaultcrypto.cs @@ -10,8 +10,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.AddColumn( + migrationBuilder.AddColumn( name: "DefaultCrypto", table: "Stores", nullable: true); diff --git a/BTCPayServer.Data/Migrations/20180114123253_events.cs b/BTCPayServer.Data/Migrations/20180114123253_events.cs index 9abc9d0e0..df9af20dc 100644 --- a/BTCPayServer.Data/Migrations/20180114123253_events.cs +++ b/BTCPayServer.Data/Migrations/20180114123253_events.cs @@ -11,13 +11,12 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "InvoiceEvents", columns: table => new { - InvoiceDataId = table.Column(nullable: false, maxLength: maxLength), - UniqueId = table.Column(nullable: false, maxLength: maxLength), + InvoiceDataId = table.Column(nullable: false, maxLength: null), + UniqueId = table.Column(nullable: false, maxLength: null), Message = table.Column(nullable: true), Timestamp = table.Column(nullable: false) }, diff --git a/BTCPayServer.Data/Migrations/20180402095640_appdata.cs b/BTCPayServer.Data/Migrations/20180402095640_appdata.cs index 07f32f64a..bd53c1072 100644 --- a/BTCPayServer.Data/Migrations/20180402095640_appdata.cs +++ b/BTCPayServer.Data/Migrations/20180402095640_appdata.cs @@ -11,17 +11,16 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "Apps", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), AppType = table.Column(nullable: true), Created = table.Column(nullable: false), Name = table.Column(nullable: true), Settings = table.Column(nullable: true), - StoreDataId = table.Column(nullable: true, maxLength: maxLength) + StoreDataId = table.Column(nullable: true, maxLength: null) }, constraints: table => { diff --git a/BTCPayServer.Data/Migrations/20180429083930_legacyapikey.cs b/BTCPayServer.Data/Migrations/20180429083930_legacyapikey.cs index 1beb80638..ce34d303f 100644 --- a/BTCPayServer.Data/Migrations/20180429083930_legacyapikey.cs +++ b/BTCPayServer.Data/Migrations/20180429083930_legacyapikey.cs @@ -10,8 +10,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "ApiKeys", columns: table => new { diff --git a/BTCPayServer.Data/Migrations/20180719095626_CanDeleteStores.cs b/BTCPayServer.Data/Migrations/20180719095626_CanDeleteStores.cs index 39e9c9235..a30065936 100644 --- a/BTCPayServer.Data/Migrations/20180719095626_CanDeleteStores.cs +++ b/BTCPayServer.Data/Migrations/20180719095626_CanDeleteStores.cs @@ -10,93 +10,89 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - if (this.SupportDropForeignKey(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropForeignKey( + migrationBuilder.DropForeignKey( + name: "FK_AddressInvoices_Invoices_InvoiceDataId", + table: "AddressInvoices"); + + migrationBuilder.DropForeignKey( + name: "FK_Apps_Stores_StoreDataId", + table: "Apps"); + + migrationBuilder.DropForeignKey( + name: "FK_Invoices_Stores_StoreDataId", + table: "Invoices"); + + migrationBuilder.DropForeignKey( + name: "FK_Payments_Invoices_InvoiceDataId", + table: "Payments"); + + migrationBuilder.DropForeignKey( + name: "FK_RefundAddresses_Invoices_InvoiceDataId", + table: "RefundAddresses"); + + migrationBuilder.AddForeignKey( name: "FK_AddressInvoices_Invoices_InvoiceDataId", - table: "AddressInvoices"); + table: "AddressInvoices", + column: "InvoiceDataId", + principalTable: "Invoices", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.DropForeignKey( - name: "FK_Apps_Stores_StoreDataId", - table: "Apps"); + migrationBuilder.AddForeignKey( + name: "FK_ApiKeys_Stores_StoreId", + table: "ApiKeys", + column: "StoreId", + principalTable: "Stores", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.DropForeignKey( - name: "FK_Invoices_Stores_StoreDataId", - table: "Invoices"); + migrationBuilder.AddForeignKey( + name: "FK_Apps_Stores_StoreDataId", + table: "Apps", + column: "StoreDataId", + principalTable: "Stores", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.DropForeignKey( - name: "FK_Payments_Invoices_InvoiceDataId", - table: "Payments"); + migrationBuilder.AddForeignKey( + name: "FK_Invoices_Stores_StoreDataId", + table: "Invoices", + column: "StoreDataId", + principalTable: "Stores", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.DropForeignKey( - name: "FK_RefundAddresses_Invoices_InvoiceDataId", - table: "RefundAddresses"); + migrationBuilder.AddForeignKey( + name: "FK_PairedSINData_Stores_StoreDataId", + table: "PairedSINData", + column: "StoreDataId", + principalTable: "Stores", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.AddForeignKey( - name: "FK_AddressInvoices_Invoices_InvoiceDataId", - table: "AddressInvoices", - column: "InvoiceDataId", - principalTable: "Invoices", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_Payments_Invoices_InvoiceDataId", + table: "Payments", + column: "InvoiceDataId", + principalTable: "Invoices", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.AddForeignKey( - name: "FK_ApiKeys_Stores_StoreId", - table: "ApiKeys", - column: "StoreId", - principalTable: "Stores", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + migrationBuilder.AddForeignKey( + name: "FK_PendingInvoices_Invoices_Id", + table: "PendingInvoices", + column: "Id", + principalTable: "Invoices", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); - migrationBuilder.AddForeignKey( - name: "FK_Apps_Stores_StoreDataId", - table: "Apps", - column: "StoreDataId", - principalTable: "Stores", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_Invoices_Stores_StoreDataId", - table: "Invoices", - column: "StoreDataId", - principalTable: "Stores", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_PairedSINData_Stores_StoreDataId", - table: "PairedSINData", - column: "StoreDataId", - principalTable: "Stores", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_Payments_Invoices_InvoiceDataId", - table: "Payments", - column: "InvoiceDataId", - principalTable: "Invoices", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_PendingInvoices_Invoices_Id", - table: "PendingInvoices", - column: "Id", - principalTable: "Invoices", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_RefundAddresses_Invoices_InvoiceDataId", - table: "RefundAddresses", - column: "InvoiceDataId", - principalTable: "Invoices", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } + migrationBuilder.AddForeignKey( + name: "FK_RefundAddresses_Invoices_InvoiceDataId", + table: "RefundAddresses", + column: "InvoiceDataId", + principalTable: "Invoices", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20190121133309_AddPaymentRequests.cs b/BTCPayServer.Data/Migrations/20190121133309_AddPaymentRequests.cs index 3902624ab..35819b286 100644 --- a/BTCPayServer.Data/Migrations/20190121133309_AddPaymentRequests.cs +++ b/BTCPayServer.Data/Migrations/20190121133309_AddPaymentRequests.cs @@ -10,13 +10,12 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "PaymentRequests", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), - StoreDataId = table.Column(nullable: true, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), + StoreDataId = table.Column(nullable: true, maxLength: null), Status = table.Column(nullable: false), Blob = table.Column(nullable: true) }, diff --git a/BTCPayServer.Data/Migrations/20190219032533_AppsTagging.cs b/BTCPayServer.Data/Migrations/20190219032533_AppsTagging.cs index ecdccd0b9..47193479b 100644 --- a/BTCPayServer.Data/Migrations/20190219032533_AppsTagging.cs +++ b/BTCPayServer.Data/Migrations/20190219032533_AppsTagging.cs @@ -10,8 +10,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.AddColumn( + migrationBuilder.AddColumn( name: "TagAllInvoices", table: "Apps", nullable: false, diff --git a/BTCPayServer.Data/Migrations/20190225091644_AddOpenIddict.cs b/BTCPayServer.Data/Migrations/20190225091644_AddOpenIddict.cs index dfcfe169a..92fe48d2b 100644 --- a/BTCPayServer.Data/Migrations/20190225091644_AddOpenIddict.cs +++ b/BTCPayServer.Data/Migrations/20190225091644_AddOpenIddict.cs @@ -11,8 +11,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "OpenIddictApplications", columns: table => new { @@ -21,13 +20,13 @@ namespace BTCPayServer.Migrations ConcurrencyToken = table.Column(maxLength: 50, nullable: true), ConsentType = table.Column(nullable: true), DisplayName = table.Column(nullable: true), - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Permissions = table.Column(nullable: true), PostLogoutRedirectUris = table.Column(nullable: true), Properties = table.Column(nullable: true), RedirectUris = table.Column(nullable: true), Type = table.Column(maxLength: 25, nullable: false), - ApplicationUserId = table.Column(nullable: true, maxLength: maxLength) + ApplicationUserId = table.Column(nullable: true, maxLength: null) }, constraints: table => { @@ -47,7 +46,7 @@ namespace BTCPayServer.Migrations ConcurrencyToken = table.Column(maxLength: 50, nullable: true), Description = table.Column(nullable: true), DisplayName = table.Column(nullable: true), - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Name = table.Column(maxLength: 200, nullable: false), Properties = table.Column(nullable: true), Resources = table.Column(nullable: true) @@ -61,9 +60,9 @@ namespace BTCPayServer.Migrations name: "OpenIddictAuthorizations", columns: table => new { - ApplicationId = table.Column(nullable: true, maxLength: maxLength), + ApplicationId = table.Column(nullable: true, maxLength: null), ConcurrencyToken = table.Column(maxLength: 50, nullable: true), - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Properties = table.Column(nullable: true), Scopes = table.Column(nullable: true), Status = table.Column(maxLength: 25, nullable: false), @@ -85,12 +84,12 @@ namespace BTCPayServer.Migrations name: "OpenIddictTokens", columns: table => new { - ApplicationId = table.Column(nullable: true, maxLength: maxLength), - AuthorizationId = table.Column(nullable: true, maxLength: maxLength), + ApplicationId = table.Column(nullable: true, maxLength: null), + AuthorizationId = table.Column(nullable: true, maxLength: null), ConcurrencyToken = table.Column(maxLength: 50, nullable: true), CreationDate = table.Column(nullable: true), ExpirationDate = table.Column(nullable: true), - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Payload = table.Column(nullable: true), Properties = table.Column(nullable: true), ReferenceId = table.Column(maxLength: 100, nullable: true), diff --git a/BTCPayServer.Data/Migrations/20190324141717_AddFiles.cs b/BTCPayServer.Data/Migrations/20190324141717_AddFiles.cs index 582510a06..d0b980674 100644 --- a/BTCPayServer.Data/Migrations/20190324141717_AddFiles.cs +++ b/BTCPayServer.Data/Migrations/20190324141717_AddFiles.cs @@ -11,16 +11,15 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "Files", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), FileName = table.Column(nullable: true), StorageFileName = table.Column(nullable: true), Timestamp = table.Column(nullable: false), - ApplicationUserId = table.Column(nullable: true, maxLength: maxLength) + ApplicationUserId = table.Column(nullable: true, maxLength: null) }, constraints: table => { diff --git a/BTCPayServer.Data/Migrations/20190425081749_AddU2fDevices.cs b/BTCPayServer.Data/Migrations/20190425081749_AddU2fDevices.cs index 276012636..505a1adee 100644 --- a/BTCPayServer.Data/Migrations/20190425081749_AddU2fDevices.cs +++ b/BTCPayServer.Data/Migrations/20190425081749_AddU2fDevices.cs @@ -10,25 +10,21 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - if (this.SupportDropColumn(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropColumn( - name: "Facade", - table: "PairedSINData"); - } + migrationBuilder.DropColumn( + name: "Facade", + table: "PairedSINData"); migrationBuilder.CreateTable( name: "U2FDevices", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Name = table.Column(nullable: true), KeyHandle = table.Column(nullable: false), PublicKey = table.Column(nullable: false), AttestationCert = table.Column(nullable: false), Counter = table.Column(nullable: false), - ApplicationUserId = table.Column(nullable: true, maxLength: maxLength) + ApplicationUserId = table.Column(nullable: true, maxLength: null) }, constraints: table => { @@ -52,13 +48,10 @@ namespace BTCPayServer.Migrations migrationBuilder.DropTable( name: "U2FDevices"); //if it did not support dropping it, then it is still here and re-adding it would throw - if (this.SupportDropColumn(migrationBuilder.ActiveProvider)) - { - migrationBuilder.AddColumn( - name: "Facade", - table: "PairedSINData", - nullable: true); - } + migrationBuilder.AddColumn( + name: "Facade", + table: "PairedSINData", + nullable: true); } } } diff --git a/BTCPayServer.Data/Migrations/20190701082105_sort_paymentrequests.cs b/BTCPayServer.Data/Migrations/20190701082105_sort_paymentrequests.cs index 8512fbd3b..6e1bb9488 100644 --- a/BTCPayServer.Data/Migrations/20190701082105_sort_paymentrequests.cs +++ b/BTCPayServer.Data/Migrations/20190701082105_sort_paymentrequests.cs @@ -11,8 +11,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.AddColumn( + migrationBuilder.AddColumn( name: "Created", table: "PaymentRequests", nullable: false, diff --git a/BTCPayServer.Data/Migrations/20190802142637_WalletData.cs b/BTCPayServer.Data/Migrations/20190802142637_WalletData.cs index f1c5d9c79..832c35030 100644 --- a/BTCPayServer.Data/Migrations/20190802142637_WalletData.cs +++ b/BTCPayServer.Data/Migrations/20190802142637_WalletData.cs @@ -10,12 +10,11 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "Wallets", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Blob = table.Column(nullable: true) }, constraints: table => @@ -27,8 +26,8 @@ namespace BTCPayServer.Migrations name: "WalletTransactions", columns: table => new { - WalletDataId = table.Column(nullable: false, maxLength: maxLength), - TransactionId = table.Column(nullable: false, maxLength: maxLength), + WalletDataId = table.Column(nullable: false, maxLength: null), + TransactionId = table.Column(nullable: false, maxLength: null), Labels = table.Column(nullable: true), Blob = table.Column(nullable: true) }, diff --git a/BTCPayServer.Data/Migrations/20200110064617_OpenIddictUpdate.cs b/BTCPayServer.Data/Migrations/20200110064617_OpenIddictUpdate.cs index 6b916efdd..f733923cf 100644 --- a/BTCPayServer.Data/Migrations/20200110064617_OpenIddictUpdate.cs +++ b/BTCPayServer.Data/Migrations/20200110064617_OpenIddictUpdate.cs @@ -11,91 +11,21 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (!migrationBuilder.IsSqlite()) - { - migrationBuilder.AlterColumn( - name: "Subject", - table: "OpenIddictTokens", - maxLength: 450, - nullable: true, - oldClrType: typeof(string), - oldMaxLength: 450); + migrationBuilder.AlterColumn( + name: "Subject", + table: "OpenIddictTokens", + maxLength: 450, + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 450); - migrationBuilder.AlterColumn( - name: "Subject", - table: "OpenIddictAuthorizations", - maxLength: 450, - nullable: true, - oldClrType: typeof(string), - oldMaxLength: 450); - } - - else - { - ReplaceOldTable(migrationBuilder, s => - { - migrationBuilder.CreateTable( - name: s, - columns: table => new - { - ApplicationId = table.Column(nullable: true, maxLength: null), - AuthorizationId = table.Column(nullable: true, maxLength: null), - ConcurrencyToken = table.Column(maxLength: 50, nullable: true), - CreationDate = table.Column(nullable: true), - ExpirationDate = table.Column(nullable: true), - Id = table.Column(nullable: false, maxLength: null), - Payload = table.Column(nullable: true), - Properties = table.Column(nullable: true), - ReferenceId = table.Column(maxLength: 100, nullable: true), - Status = table.Column(maxLength: 25, nullable: false), - Subject = table.Column(maxLength: 450, nullable: true), - Type = table.Column(maxLength: 25, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OpenIddictTokens", x => x.Id); - table.ForeignKey( - name: "FK_OpenIddictTokens_OpenIddictApplications_ApplicationId", - column: x => x.ApplicationId, - principalTable: "OpenIddictApplications", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_OpenIddictTokens_OpenIddictAuthorizations_AuthorizationId", - column: x => x.AuthorizationId, - principalTable: "OpenIddictAuthorizations", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - }, "OpenIddictTokens"); - - ReplaceOldTable(migrationBuilder, s => - { - migrationBuilder.CreateTable( - name: s, - columns: table => new - { - ApplicationId = table.Column(nullable: true, maxLength: null), - ConcurrencyToken = table.Column(maxLength: 50, nullable: true), - Id = table.Column(nullable: false, maxLength: null), - Properties = table.Column(nullable: true), - Scopes = table.Column(nullable: true), - Status = table.Column(maxLength: 25, nullable: false), - Subject = table.Column(maxLength: 450, nullable: true), - Type = table.Column(maxLength: 25, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OpenIddictAuthorizations", x => x.Id); - table.ForeignKey( - name: "FK_OpenIddictAuthorizations_OpenIddictApplications_ApplicationId", - column: x => x.ApplicationId, - principalTable: "OpenIddictApplications", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - }, "OpenIddictAuthorizations"); - } + migrationBuilder.AlterColumn( + name: "Subject", + table: "OpenIddictAuthorizations", + maxLength: 450, + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 450); migrationBuilder.AddColumn( name: "Requirements", @@ -105,140 +35,27 @@ namespace BTCPayServer.Migrations protected override void Down(MigrationBuilder migrationBuilder) { - if (!migrationBuilder.IsSqlite()) - { - migrationBuilder.DropColumn( - name: "Requirements", - table: "OpenIddictApplications"); + migrationBuilder.DropColumn( + name: "Requirements", + table: "OpenIddictApplications"); - migrationBuilder.AlterColumn( - name: "Subject", - table: "OpenIddictTokens", - maxLength: 450, - nullable: false, - oldClrType: typeof(string), - oldMaxLength: 450, - oldNullable: true); + migrationBuilder.AlterColumn( + name: "Subject", + table: "OpenIddictTokens", + maxLength: 450, + nullable: false, + oldClrType: typeof(string), + oldMaxLength: 450, + oldNullable: true); - migrationBuilder.AlterColumn( - name: "Subject", - table: "OpenIddictAuthorizations", - maxLength: 450, - nullable: false, - oldClrType: typeof(string), - oldMaxLength: 450, - oldNullable: true); - } - else - { - ReplaceOldTable(migrationBuilder, s => - { - migrationBuilder.CreateTable( - name: s, - columns: table => new - { - ApplicationId = table.Column(nullable: true, maxLength: null), - AuthorizationId = table.Column(nullable: true, maxLength: null), - ConcurrencyToken = table.Column(maxLength: 50, nullable: true), - CreationDate = table.Column(nullable: true), - ExpirationDate = table.Column(nullable: true), - Id = table.Column(nullable: false, maxLength: null), - Payload = table.Column(nullable: true), - Properties = table.Column(nullable: true), - ReferenceId = table.Column(maxLength: 100, nullable: true), - Status = table.Column(maxLength: 25, nullable: false), - Subject = table.Column(maxLength: 450, nullable: false), - Type = table.Column(maxLength: 25, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OpenIddictTokens", x => x.Id); - table.ForeignKey( - name: "FK_OpenIddictTokens_OpenIddictApplications_ApplicationId", - column: x => x.ApplicationId, - principalTable: "OpenIddictApplications", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_OpenIddictTokens_OpenIddictAuthorizations_AuthorizationId", - column: x => x.AuthorizationId, - principalTable: "OpenIddictAuthorizations", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - }, "OpenIddictTokens", "WHERE Subject IS NOT NULL"); - - ReplaceOldTable(migrationBuilder, s => - { - migrationBuilder.CreateTable( - name: s, - columns: table => new - { - ApplicationId = table.Column(nullable: true, maxLength: null), - ConcurrencyToken = table.Column(maxLength: 50, nullable: true), - Id = table.Column(nullable: false, maxLength: null), - Properties = table.Column(nullable: true), - Scopes = table.Column(nullable: true), - Status = table.Column(maxLength: 25, nullable: false), - Subject = table.Column(maxLength: 450, nullable: false), - Type = table.Column(maxLength: 25, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OpenIddictAuthorizations", x => x.Id); - table.ForeignKey( - name: "FK_OpenIddictAuthorizations_OpenIddictApplications_ApplicationId", - column: x => x.ApplicationId, - principalTable: "OpenIddictApplications", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - }, "OpenIddictAuthorizations", "WHERE Subject IS NOT NULL"); - - ReplaceOldTable(migrationBuilder, s => - { - migrationBuilder.CreateTable( - name: s, - columns: table => new - { - ClientId = table.Column(maxLength: 100, nullable: false), - ClientSecret = table.Column(nullable: true), - ConcurrencyToken = table.Column(maxLength: 50, nullable: true), - ConsentType = table.Column(nullable: true), - DisplayName = table.Column(nullable: true), - Id = table.Column(nullable: false, maxLength: null), - Permissions = table.Column(nullable: true), - PostLogoutRedirectUris = table.Column(nullable: true), - Properties = table.Column(nullable: true), - RedirectUris = table.Column(nullable: true), - Type = table.Column(maxLength: 25, nullable: false), - ApplicationUserId = table.Column(nullable: true, maxLength: null) - }, - constraints: table => - { - table.PrimaryKey("PK_OpenIddictApplications", x => x.Id); - table.ForeignKey( - name: "FK_OpenIddictApplications_AspNetUsers_ApplicationUserId", - column: x => x.ApplicationUserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - }, "OpenIddictApplications", "", - "ClientId, ClientSecret, ConcurrencyToken, ConsentType, DisplayName, Id, Permissions, PostLogoutRedirectUris, Properties, RedirectUris, Type, ApplicationUserId"); - } - } - - private void ReplaceOldTable(MigrationBuilder migrationBuilder, Action createTable, string tableName, - string whereClause = "", string columns = "*") - { - createTable.Invoke($"New_{tableName}"); - migrationBuilder.Sql( - $"INSERT INTO New_{tableName} {(columns == "*" ? string.Empty : $"({columns})")}SELECT {columns} FROM {tableName} {whereClause};"); - migrationBuilder.Sql("PRAGMA foreign_keys=\"0\"", true); - migrationBuilder.Sql($"DROP TABLE {tableName}", true); - migrationBuilder.Sql($"ALTER TABLE New_{tableName} RENAME TO {tableName}", true); - migrationBuilder.Sql("PRAGMA foreign_keys=\"1\"", true); + migrationBuilder.AlterColumn( + name: "Subject", + table: "OpenIddictAuthorizations", + maxLength: 450, + nullable: false, + oldClrType: typeof(string), + oldMaxLength: 450, + oldNullable: true); } } } diff --git a/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs b/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs index 56bfe8629..38a4bf072 100644 --- a/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs +++ b/BTCPayServer.Data/Migrations/20200119130108_ExtendApiKeys.cs @@ -31,44 +31,37 @@ namespace BTCPayServer.Migrations name: "IX_ApiKeys_UserId", table: "ApiKeys", column: "UserId"); - if (this.SupportAddForeignKey(migrationBuilder.ActiveProvider)) - { - migrationBuilder.AddForeignKey( - name: "FK_ApiKeys_AspNetUsers_UserId", - table: "ApiKeys", - column: "UserId", - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } + + migrationBuilder.AddForeignKey( + name: "FK_ApiKeys_AspNetUsers_UserId", + table: "ApiKeys", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } protected override void Down(MigrationBuilder migrationBuilder) { - if (this.SupportDropForeignKey(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropForeignKey( - name: "FK_ApiKeys_AspNetUsers_UserId", - table: "ApiKeys"); - } + migrationBuilder.DropForeignKey( + name: "FK_ApiKeys_AspNetUsers_UserId", + table: "ApiKeys"); migrationBuilder.DropIndex( name: "IX_ApiKeys_UserId", table: "ApiKeys"); - if (this.SupportDropColumn(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropColumn( - name: "Permissions", - table: "ApiKeys"); - migrationBuilder.DropColumn( - name: "Type", - table: "ApiKeys"); + migrationBuilder.DropColumn( + name: "Permissions", + table: "ApiKeys"); - migrationBuilder.DropColumn( - name: "UserId", - table: "ApiKeys"); - } + migrationBuilder.DropColumn( + name: "Type", + table: "ApiKeys"); + + migrationBuilder.DropColumn( + name: "UserId", + table: "ApiKeys"); } } } diff --git a/BTCPayServer.Data/Migrations/20200224134444_Remove_OpenIddict.cs b/BTCPayServer.Data/Migrations/20200224134444_Remove_OpenIddict.cs index 2626f9da3..9cd7d588e 100644 --- a/BTCPayServer.Data/Migrations/20200224134444_Remove_OpenIddict.cs +++ b/BTCPayServer.Data/Migrations/20200224134444_Remove_OpenIddict.cs @@ -26,13 +26,12 @@ namespace BTCPayServer.Migrations protected override void Down(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "OpenIddictApplications", columns: table => new { - Id = table.Column(type: "TEXT", nullable: false, maxLength: maxLength), - ApplicationUserId = table.Column(type: "TEXT", nullable: true, maxLength: maxLength), + Id = table.Column(type: "TEXT", nullable: false, maxLength: null), + ApplicationUserId = table.Column(type: "TEXT", nullable: true, maxLength: null), ClientId = table.Column(type: "TEXT", maxLength: 100, nullable: false), ClientSecret = table.Column(type: "TEXT", nullable: true), ConcurrencyToken = table.Column(type: "TEXT", maxLength: 50, nullable: true), @@ -60,7 +59,7 @@ namespace BTCPayServer.Migrations name: "OpenIddictScopes", columns: table => new { - Id = table.Column(type: "TEXT", nullable: false, maxLength: maxLength), + Id = table.Column(type: "TEXT", nullable: false, maxLength: null), ConcurrencyToken = table.Column(type: "TEXT", maxLength: 50, nullable: true), Description = table.Column(type: "TEXT", nullable: true), DisplayName = table.Column(type: "TEXT", nullable: true), @@ -77,8 +76,8 @@ namespace BTCPayServer.Migrations name: "OpenIddictAuthorizations", columns: table => new { - Id = table.Column(type: "TEXT", nullable: false, maxLength: maxLength), - ApplicationId = table.Column(type: "TEXT", nullable: true, maxLength: maxLength), + Id = table.Column(type: "TEXT", nullable: false, maxLength: null), + ApplicationId = table.Column(type: "TEXT", nullable: true, maxLength: null), ConcurrencyToken = table.Column(type: "TEXT", maxLength: 50, nullable: true), Properties = table.Column(type: "TEXT", nullable: true), Scopes = table.Column(type: "TEXT", nullable: true), @@ -101,9 +100,9 @@ namespace BTCPayServer.Migrations name: "OpenIddictTokens", columns: table => new { - Id = table.Column(type: "TEXT", nullable: false, maxLength: maxLength), - ApplicationId = table.Column(type: "TEXT", nullable: true, maxLength: maxLength), - AuthorizationId = table.Column(type: "TEXT", nullable: true, maxLength: maxLength), + Id = table.Column(type: "TEXT", nullable: false, maxLength: null), + ApplicationId = table.Column(type: "TEXT", nullable: true, maxLength: null), + AuthorizationId = table.Column(type: "TEXT", nullable: true, maxLength: null), ConcurrencyToken = table.Column(type: "TEXT", maxLength: 50, nullable: true), CreationDate = table.Column(type: "TEXT", nullable: true), ExpirationDate = table.Column(type: "TEXT", nullable: true), diff --git a/BTCPayServer.Data/Migrations/20200402065615_AddApiKeyBlob.cs b/BTCPayServer.Data/Migrations/20200402065615_AddApiKeyBlob.cs index 4787e8fc6..75ccad888 100644 --- a/BTCPayServer.Data/Migrations/20200402065615_AddApiKeyBlob.cs +++ b/BTCPayServer.Data/Migrations/20200402065615_AddApiKeyBlob.cs @@ -10,12 +10,9 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (this.SupportDropColumn(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropColumn( - name: "Permissions", - table: "ApiKeys"); - } + migrationBuilder.DropColumn( + name: "Permissions", + table: "ApiKeys"); migrationBuilder.AddColumn( name: "Blob", @@ -25,12 +22,9 @@ namespace BTCPayServer.Migrations protected override void Down(MigrationBuilder migrationBuilder) { - if (this.SupportDropColumn(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropColumn( - name: "Blob", - table: "ApiKeys"); - } + migrationBuilder.DropColumn( + name: "Blob", + table: "ApiKeys"); migrationBuilder.AddColumn( name: "Permissions", diff --git a/BTCPayServer.Data/Migrations/20200507092343_AddArchivedToInvoice.cs b/BTCPayServer.Data/Migrations/20200507092343_AddArchivedToInvoice.cs index f514cb18f..8ca84c83d 100644 --- a/BTCPayServer.Data/Migrations/20200507092343_AddArchivedToInvoice.cs +++ b/BTCPayServer.Data/Migrations/20200507092343_AddArchivedToInvoice.cs @@ -24,15 +24,12 @@ namespace BTCPayServer.Migrations protected override void Down(MigrationBuilder migrationBuilder) { - if (this.SupportDropColumn(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropColumn( - name: "Archived", - table: "Invoices"); - migrationBuilder.DropColumn( - name: "Archived", - table: "PaymentRequests"); - } + migrationBuilder.DropColumn( + name: "Archived", + table: "Invoices"); + migrationBuilder.DropColumn( + name: "Archived", + table: "PaymentRequests"); } } } diff --git a/BTCPayServer.Data/Migrations/20200625064111_refundnotificationpullpayments.cs b/BTCPayServer.Data/Migrations/20200625064111_refundnotificationpullpayments.cs index 94ebe854a..56032cf04 100644 --- a/BTCPayServer.Data/Migrations/20200625064111_refundnotificationpullpayments.cs +++ b/BTCPayServer.Data/Migrations/20200625064111_refundnotificationpullpayments.cs @@ -11,8 +11,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - + migrationBuilder.DropTable( name: "RefundAddresses"); @@ -20,7 +19,7 @@ namespace BTCPayServer.Migrations name: "CurrentRefundId", table: "Invoices", nullable: true, - maxLength: maxLength); + maxLength: null); migrationBuilder.CreateTable( name: "Notifications", @@ -76,7 +75,7 @@ namespace BTCPayServer.Migrations PullPaymentDataId = table.Column(maxLength: 30, nullable: true), State = table.Column(maxLength: 20, nullable: false), PaymentMethodId = table.Column(maxLength: 20, nullable: false), - Destination = table.Column(maxLength: maxLength, nullable: true), + Destination = table.Column(maxLength: null, nullable: true), Blob = table.Column(nullable: true), Proof = table.Column(nullable: true) }, @@ -95,8 +94,8 @@ namespace BTCPayServer.Migrations name: "Refunds", columns: table => new { - InvoiceDataId = table.Column(maxLength: maxLength, nullable: false), - PullPaymentDataId = table.Column(maxLength: maxLength, nullable: false) + InvoiceDataId = table.Column(maxLength: null, nullable: false), + PullPaymentDataId = table.Column(maxLength: null, nullable: false) }, constraints: table => { @@ -151,14 +150,13 @@ namespace BTCPayServer.Migrations table: "Refunds", column: "PullPaymentDataId"); - if (this.SupportAddForeignKey(this.ActiveProvider)) - migrationBuilder.AddForeignKey( - name: "FK_Invoices_Refunds_Id_CurrentRefundId", - table: "Invoices", - columns: new[] { "Id", "CurrentRefundId" }, - principalTable: "Refunds", - principalColumns: new[] { "InvoiceDataId", "PullPaymentDataId" }, - onDelete: ReferentialAction.Restrict); + migrationBuilder.AddForeignKey( + name: "FK_Invoices_Refunds_Id_CurrentRefundId", + table: "Invoices", + columns: new[] { "Id", "CurrentRefundId" }, + principalTable: "Refunds", + principalColumns: new[] { "InvoiceDataId", "PullPaymentDataId" }, + onDelete: ReferentialAction.Restrict); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20200901161733_AddInvoiceEventLogSeverity.cs b/BTCPayServer.Data/Migrations/20200901161733_AddInvoiceEventLogSeverity.cs index f04d54534..638536b33 100644 --- a/BTCPayServer.Data/Migrations/20200901161733_AddInvoiceEventLogSeverity.cs +++ b/BTCPayServer.Data/Migrations/20200901161733_AddInvoiceEventLogSeverity.cs @@ -20,13 +20,9 @@ namespace BTCPayServer.Migrations protected override void Down(MigrationBuilder migrationBuilder) { - if (this.SupportDropColumn(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropColumn( - name: "Severity", - table: "InvoiceEvents"); - - } + migrationBuilder.DropColumn( + name: "Severity", + table: "InvoiceEvents"); } } } diff --git a/BTCPayServer.Data/Migrations/20201002145033_AddCreateDateToUser.cs b/BTCPayServer.Data/Migrations/20201002145033_AddCreateDateToUser.cs index b148e730b..b98869176 100644 --- a/BTCPayServer.Data/Migrations/20201002145033_AddCreateDateToUser.cs +++ b/BTCPayServer.Data/Migrations/20201002145033_AddCreateDateToUser.cs @@ -19,13 +19,9 @@ namespace BTCPayServer.Migrations protected override void Down(MigrationBuilder migrationBuilder) { - if (this.SupportDropColumn(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropColumn( - name: "Created", - table: "AspNetUsers"); - - } + migrationBuilder.DropColumn( + name: "Created", + table: "AspNetUsers"); } } } diff --git a/BTCPayServer.Data/Migrations/20201007090617_u2fDeviceCascade.cs b/BTCPayServer.Data/Migrations/20201007090617_u2fDeviceCascade.cs index 1df268191..3238710ed 100644 --- a/BTCPayServer.Data/Migrations/20201007090617_u2fDeviceCascade.cs +++ b/BTCPayServer.Data/Migrations/20201007090617_u2fDeviceCascade.cs @@ -10,38 +10,32 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (this.SupportDropForeignKey(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropForeignKey( - name: "FK_U2FDevices_AspNetUsers_ApplicationUserId", - table: "U2FDevices"); + migrationBuilder.DropForeignKey( + name: "FK_U2FDevices_AspNetUsers_ApplicationUserId", + table: "U2FDevices"); - migrationBuilder.AddForeignKey( - name: "FK_U2FDevices_AspNetUsers_ApplicationUserId", - table: "U2FDevices", - column: "ApplicationUserId", - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } + migrationBuilder.AddForeignKey( + name: "FK_U2FDevices_AspNetUsers_ApplicationUserId", + table: "U2FDevices", + column: "ApplicationUserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } protected override void Down(MigrationBuilder migrationBuilder) { - if (this.SupportDropForeignKey(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropForeignKey( - name: "FK_U2FDevices_AspNetUsers_ApplicationUserId", - table: "U2FDevices"); + migrationBuilder.DropForeignKey( + name: "FK_U2FDevices_AspNetUsers_ApplicationUserId", + table: "U2FDevices"); - migrationBuilder.AddForeignKey( - name: "FK_U2FDevices_AspNetUsers_ApplicationUserId", - table: "U2FDevices", - column: "ApplicationUserId", - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - } + migrationBuilder.AddForeignKey( + name: "FK_U2FDevices_AspNetUsers_ApplicationUserId", + table: "U2FDevices", + column: "ApplicationUserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); } } } diff --git a/BTCPayServer.Data/Migrations/20201208054211_invoicesorderindex.cs b/BTCPayServer.Data/Migrations/20201208054211_invoicesorderindex.cs index cf596e620..3c0666061 100644 --- a/BTCPayServer.Data/Migrations/20201208054211_invoicesorderindex.cs +++ b/BTCPayServer.Data/Migrations/20201208054211_invoicesorderindex.cs @@ -10,15 +10,12 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (!migrationBuilder.IsSqlite()) - { - migrationBuilder.AlterColumn( - name: "OrderId", - table: "Invoices", - maxLength: 100, - nullable: true, - oldClrType: typeof(string)); - } + migrationBuilder.AlterColumn( + name: "OrderId", + table: "Invoices", + maxLength: 100, + nullable: true, + oldClrType: typeof(string)); migrationBuilder.CreateIndex( name: "IX_Invoices_OrderId", diff --git a/BTCPayServer.Data/Migrations/20210314092253_Fido2Credentials.cs b/BTCPayServer.Data/Migrations/20210314092253_Fido2Credentials.cs index 246079fe5..8e7126d32 100644 --- a/BTCPayServer.Data/Migrations/20210314092253_Fido2Credentials.cs +++ b/BTCPayServer.Data/Migrations/20210314092253_Fido2Credentials.cs @@ -11,14 +11,13 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "Fido2Credentials", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), Name = table.Column(nullable: true), - ApplicationUserId = table.Column(nullable: true, maxLength: maxLength), + ApplicationUserId = table.Column(nullable: true, maxLength: null), Blob = table.Column(nullable: true), Type = table.Column(nullable: false) }, diff --git a/BTCPayServer.Data/Migrations/20220311135252_AddPayoutProcessors.cs b/BTCPayServer.Data/Migrations/20220311135252_AddPayoutProcessors.cs index 37deb5ec8..2c1e8fdc0 100644 --- a/BTCPayServer.Data/Migrations/20220311135252_AddPayoutProcessors.cs +++ b/BTCPayServer.Data/Migrations/20220311135252_AddPayoutProcessors.cs @@ -17,19 +17,18 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; migrationBuilder.AddColumn( - name: "StoreDataId", - table: "Payouts", - nullable: true, - maxLength: maxLength); + name: "StoreDataId", + table: "Payouts", + nullable: true, + maxLength: null); migrationBuilder.CreateTable( name: "PayoutProcessors", columns: table => new { - Id = table.Column(nullable: false, maxLength: maxLength), - StoreId = table.Column(nullable: true, maxLength: maxLength), + Id = table.Column(nullable: false, maxLength: null), + StoreId = table.Column(nullable: true, maxLength: null), PaymentMethod = table.Column(nullable: true), Processor = table.Column(nullable: true), Blob = table.Column(nullable: true) @@ -54,40 +53,31 @@ namespace BTCPayServer.Migrations name: "IX_PayoutProcessors_StoreId", table: "PayoutProcessors", column: "StoreId"); - if (this.SupportAddForeignKey(ActiveProvider)) - { - migrationBuilder.AddForeignKey( - name: "FK_Payouts_Stores_StoreDataId", - table: "Payouts", - column: "StoreDataId", - principalTable: "Stores", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } + + migrationBuilder.AddForeignKey( + name: "FK_Payouts_Stores_StoreDataId", + table: "Payouts", + column: "StoreDataId", + principalTable: "Stores", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } protected override void Down(MigrationBuilder migrationBuilder) { - if (this.SupportDropForeignKey(ActiveProvider)) - { + migrationBuilder.DropForeignKey( + name: "FK_Payouts_Stores_StoreDataId", + table: "Payouts"); - migrationBuilder.DropForeignKey( - name: "FK_Payouts_Stores_StoreDataId", - table: "Payouts"); - migrationBuilder.DropTable( name: "PayoutProcessors"); migrationBuilder.DropIndex( name: "IX_Payouts_StoreDataId", table: "Payouts"); - } - if(this.SupportDropColumn(ActiveProvider)) - { migrationBuilder.DropColumn( name: "StoreDataId", table: "Payouts"); - } } } } diff --git a/BTCPayServer.Data/Migrations/20220414132313_AddLightningAddress.cs b/BTCPayServer.Data/Migrations/20220414132313_AddLightningAddress.cs index 7fc81525e..40f29469b 100644 --- a/BTCPayServer.Data/Migrations/20220414132313_AddLightningAddress.cs +++ b/BTCPayServer.Data/Migrations/20220414132313_AddLightningAddress.cs @@ -17,13 +17,12 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; - migrationBuilder.CreateTable( + migrationBuilder.CreateTable( name: "LightningAddresses", columns: table => new { - Username = table.Column(nullable: false, maxLength: maxLength), - StoreDataId = table.Column(nullable: false, maxLength: maxLength), + Username = table.Column(nullable: false, maxLength: null), + StoreDataId = table.Column(nullable: false, maxLength: null), Blob = table.Column( nullable: true) }, constraints: table => diff --git a/BTCPayServer.Data/Migrations/20220610090843_AddSettingsToStore.cs b/BTCPayServer.Data/Migrations/20220610090843_AddSettingsToStore.cs index bfebcf0ba..f65c55276 100644 --- a/BTCPayServer.Data/Migrations/20220610090843_AddSettingsToStore.cs +++ b/BTCPayServer.Data/Migrations/20220610090843_AddSettingsToStore.cs @@ -14,14 +14,13 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxlength = migrationBuilder.IsMySql() ? 255 : null; migrationBuilder.CreateTable( name: "StoreSettings", columns: table => new { - Name = table.Column(nullable: false, maxLength: maxlength), - StoreId = table.Column(nullable: false, maxLength: maxlength), - Value = table.Column(type: migrationBuilder.IsNpgsql() ? "JSONB" : "TEXT", nullable: true) + Name = table.Column(nullable: false, maxLength: null), + StoreId = table.Column(nullable: false, maxLength: null), + Value = table.Column(type: "JSONB", nullable: true) }, constraints: table => { diff --git a/BTCPayServer.Data/Migrations/20220929132704_label.cs b/BTCPayServer.Data/Migrations/20220929132704_label.cs index 7a167329d..c81837d8f 100644 --- a/BTCPayServer.Data/Migrations/20220929132704_label.cs +++ b/BTCPayServer.Data/Migrations/20220929132704_label.cs @@ -17,16 +17,14 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxlength = migrationBuilder.IsMySql() ? 255 : null; - migrationBuilder.CreateTable( name: "WalletObjects", columns: table => new { - WalletId = table.Column(nullable: false, maxLength: maxlength), - Type = table.Column(nullable: false, maxLength: maxlength), - Id = table.Column(nullable: false, maxLength: maxlength), - Data = table.Column(type: migrationBuilder.IsNpgsql() ? "JSONB" : "TEXT", nullable: true) + WalletId = table.Column(nullable: false, maxLength: null), + Type = table.Column(nullable: false, maxLength: null), + Id = table.Column(nullable: false, maxLength: null), + Data = table.Column(type: "JSONB", nullable: true) }, constraints: table => { @@ -37,18 +35,16 @@ namespace BTCPayServer.Migrations table: "WalletObjects", columns: new[] { "Type", "Id" }); - - maxlength = migrationBuilder.IsMySql() ? 100 : null; migrationBuilder.CreateTable( name: "WalletObjectLinks", columns: table => new { - WalletId = table.Column(nullable: false, maxLength: maxlength), - AType = table.Column(nullable: false, maxLength: maxlength), - AId = table.Column(nullable: false, maxLength: maxlength), - BType = table.Column(nullable: false, maxLength: maxlength), - BId = table.Column(nullable: false, maxLength: maxlength), - Data = table.Column(type: migrationBuilder.IsNpgsql() ? "JSONB" : "TEXT", nullable: true) + WalletId = table.Column(nullable: false, maxLength: null), + AType = table.Column(nullable: false, maxLength: null), + AId = table.Column(nullable: false, maxLength: null), + BType = table.Column(nullable: false, maxLength: null), + BId = table.Column(nullable: false, maxLength: null), + Data = table.Column(type: "JSONB", nullable: true) }, constraints: table => { diff --git a/BTCPayServer.Data/Migrations/20221128062447_jsonb.cs b/BTCPayServer.Data/Migrations/20221128062447_jsonb.cs index d69070272..2366af138 100644 --- a/BTCPayServer.Data/Migrations/20221128062447_jsonb.cs +++ b/BTCPayServer.Data/Migrations/20221128062447_jsonb.cs @@ -16,11 +16,8 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (migrationBuilder.IsNpgsql()) - { - migrationBuilder.Sql("ALTER TABLE \"Settings\" ALTER COLUMN \"Value\" TYPE JSONB USING \"Value\"::JSONB"); - migrationBuilder.Sql("ALTER TABLE \"Stores\" ALTER COLUMN \"StoreBlob\" TYPE JSONB USING regexp_replace(convert_from(\"StoreBlob\",'UTF8'), '\\\\u0000', '', 'g')::JSONB"); - } + migrationBuilder.Sql("ALTER TABLE \"Settings\" ALTER COLUMN \"Value\" TYPE JSONB USING \"Value\"::JSONB"); + migrationBuilder.Sql("ALTER TABLE \"Stores\" ALTER COLUMN \"StoreBlob\" TYPE JSONB USING regexp_replace(convert_from(\"StoreBlob\",'UTF8'), '\\\\u0000', '', 'g')::JSONB"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20230123062447_migrateoldratesource.cs b/BTCPayServer.Data/Migrations/20230123062447_migrateoldratesource.cs index 0c802c700..19bc9be31 100644 --- a/BTCPayServer.Data/Migrations/20230123062447_migrateoldratesource.cs +++ b/BTCPayServer.Data/Migrations/20230123062447_migrateoldratesource.cs @@ -16,10 +16,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (migrationBuilder.IsNpgsql()) - { - migrationBuilder.Sql("UPDATE \"Stores\" SET \"StoreBlob\"=jsonb_set(\"StoreBlob\", \'{preferredExchange}\', \'{\"oasis_trade\": \"oasisdev\", \"gdax\":\"coinbasepro\", \"coinaverage\":\"coingecko\"}\'::jsonb->(\"StoreBlob\"->>\'preferredExchange\')) WHERE \"StoreBlob\"->>\'preferredExchange\' = ANY (ARRAY[\'oasis_trade\', \'gdax\', \'coinaverage\']);"); - } + migrationBuilder.Sql("UPDATE \"Stores\" SET \"StoreBlob\"=jsonb_set(\"StoreBlob\", \'{preferredExchange}\', \'{\"oasis_trade\": \"oasisdev\", \"gdax\":\"coinbasepro\", \"coinaverage\":\"coingecko\"}\'::jsonb->(\"StoreBlob\"->>\'preferredExchange\')) WHERE \"StoreBlob\"->>\'preferredExchange\' = ANY (ARRAY[\'oasis_trade\', \'gdax\', \'coinaverage\']);"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20230125085242_AddForms.cs b/BTCPayServer.Data/Migrations/20230125085242_AddForms.cs index 168d532dd..705bc8c2b 100644 --- a/BTCPayServer.Data/Migrations/20230125085242_AddForms.cs +++ b/BTCPayServer.Data/Migrations/20230125085242_AddForms.cs @@ -16,15 +16,14 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - int? maxlength = migrationBuilder.IsMySql() ? 255 : null; migrationBuilder.CreateTable( name: "Forms", columns: table => new { - Id = table.Column(type: "TEXT", nullable: false, maxLength: maxlength), - Name = table.Column(type: "TEXT", nullable: true, maxLength: maxlength), - StoreId = table.Column(type: "TEXT", nullable: true, maxLength: maxlength), - Config = table.Column(type: migrationBuilder.IsNpgsql() ? "JSONB" : "TEXT", nullable: true), + Id = table.Column(type: "TEXT", nullable: false, maxLength: null), + Name = table.Column(type: "TEXT", nullable: true, maxLength: null), + StoreId = table.Column(type: "TEXT", nullable: true, maxLength: null), + Config = table.Column(type: "JSONB", nullable: true), Public = table.Column(nullable: false) }, constraints: table => diff --git a/BTCPayServer.Data/Migrations/20230130040047_blob2.cs b/BTCPayServer.Data/Migrations/20230130040047_blob2.cs index 09a22f98d..1286da2a7 100644 --- a/BTCPayServer.Data/Migrations/20230130040047_blob2.cs +++ b/BTCPayServer.Data/Migrations/20230130040047_blob2.cs @@ -14,76 +14,75 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - var type = migrationBuilder.IsNpgsql() ? "JSONB" : "TEXT"; migrationBuilder.AddColumn( name: "Blob2", table: "Webhooks", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "WebhookDeliveries", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "PaymentRequests", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "Notifications", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "LightningAddresses", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "Fido2Credentials", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "AspNetUsers", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "ApiKeys", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "Invoices", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "Payments", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "PayoutProcessors", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( name: "Blob2", table: "CustodianAccount", - type: type, + type: "JSONB", nullable: true); migrationBuilder.AddColumn( diff --git a/BTCPayServer.Data/Migrations/20230130062447_jsonb2.cs b/BTCPayServer.Data/Migrations/20230130062447_jsonb2.cs index 96dca6791..426082672 100644 --- a/BTCPayServer.Data/Migrations/20230130062447_jsonb2.cs +++ b/BTCPayServer.Data/Migrations/20230130062447_jsonb2.cs @@ -16,10 +16,7 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (migrationBuilder.IsNpgsql()) - { - migrationBuilder.Sql("ALTER TABLE \"Stores\" ALTER COLUMN \"DerivationStrategies\" TYPE JSONB USING \"DerivationStrategies\"::JSONB"); - } + migrationBuilder.Sql("ALTER TABLE \"Stores\" ALTER COLUMN \"DerivationStrategies\" TYPE JSONB USING \"DerivationStrategies\"::JSONB"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20230315062447_fixmaxlength.cs b/BTCPayServer.Data/Migrations/20230315062447_fixmaxlength.cs index 0ab9f3c88..443b87a36 100644 --- a/BTCPayServer.Data/Migrations/20230315062447_fixmaxlength.cs +++ b/BTCPayServer.Data/Migrations/20230315062447_fixmaxlength.cs @@ -16,11 +16,8 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - if (migrationBuilder.IsNpgsql()) - { - migrationBuilder.Sql("ALTER TABLE \"InvoiceSearches\" ALTER COLUMN \"Value\" TYPE TEXT USING \"Value\"::TEXT;"); - migrationBuilder.Sql("ALTER TABLE \"Invoices\" ALTER COLUMN \"OrderId\" TYPE TEXT USING \"OrderId\"::TEXT;"); - } + migrationBuilder.Sql("ALTER TABLE \"InvoiceSearches\" ALTER COLUMN \"Value\" TYPE TEXT USING \"Value\"::TEXT;"); + migrationBuilder.Sql("ALTER TABLE \"Invoices\" ALTER COLUMN \"OrderId\" TYPE TEXT USING \"OrderId\"::TEXT;"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/BTCPayServer.Data/Migrations/20230504125505_StoreRoles.cs b/BTCPayServer.Data/Migrations/20230504125505_StoreRoles.cs index ffc91258c..2c21f1c93 100644 --- a/BTCPayServer.Data/Migrations/20230504125505_StoreRoles.cs +++ b/BTCPayServer.Data/Migrations/20230504125505_StoreRoles.cs @@ -17,7 +17,6 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { - var permissionsType = migrationBuilder.IsNpgsql() ? "TEXT[]" : "TEXT"; migrationBuilder.CreateTable( name: "StoreRoles", columns: table => new @@ -25,7 +24,7 @@ namespace BTCPayServer.Migrations Id = table.Column(type: "TEXT", nullable: false), StoreDataId = table.Column(type: "TEXT", nullable: true), Role = table.Column(type: "TEXT", nullable: false), - Permissions = table.Column(type: permissionsType, nullable: false) + Permissions = table.Column(type: "TEXT[]", nullable: false) }, constraints: table => { @@ -44,60 +43,45 @@ namespace BTCPayServer.Migrations columns: new[] { "StoreDataId", "Role" }, unique: true); - object GetPermissionsData(string[] permissions) - { - if (migrationBuilder.IsNpgsql()) - return permissions; - return JsonConvert.SerializeObject(permissions); - } - migrationBuilder.InsertData( "StoreRoles", columns: new[] { "Id", "Role", "Permissions" }, - columnTypes: new[] { "TEXT", "TEXT", permissionsType }, + columnTypes: new[] { "TEXT", "TEXT", "TEXT[]" }, values: new object[,] { { - "Owner", "Owner", GetPermissionsData(new[] + "Owner", "Owner", new[] { "btcpay.store.canmodifystoresettings", "btcpay.store.cantradecustodianaccount", "btcpay.store.canwithdrawfromcustodianaccount", "btcpay.store.candeposittocustodianaccount" - }) + } }, { - "Guest", "Guest", GetPermissionsData(new[] + "Guest", "Guest", new[] { "btcpay.store.canviewstoresettings", "btcpay.store.canmodifyinvoices", "btcpay.store.canviewcustodianaccounts", "btcpay.store.candeposittocustodianaccount" - }) + } } }); - if (this.SupportAddForeignKey(migrationBuilder.ActiveProvider)) - { - - migrationBuilder.AddForeignKey( - name: "FK_UserStore_StoreRoles_Role", - table: "UserStore", - column: "Role", - principalTable: "StoreRoles", - principalColumn: "Id"); - } + migrationBuilder.AddForeignKey( + name: "FK_UserStore_StoreRoles_Role", + table: "UserStore", + column: "Role", + principalTable: "StoreRoles", + principalColumn: "Id"); } protected override void Down(MigrationBuilder migrationBuilder) { - - if (this.SupportDropForeignKey(migrationBuilder.ActiveProvider)) - { - migrationBuilder.DropForeignKey( - name: "FK_UserStore_StoreRoles_Role", - table: "UserStore"); - } + migrationBuilder.DropForeignKey( + name: "FK_UserStore_StoreRoles_Role", + table: "UserStore"); migrationBuilder.DropTable( name: "StoreRoles"); diff --git a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs index 54ce908c2..bc3a95945 100644 --- a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,5 +1,6 @@ // using System; +using System.Collections.Generic; using BTCPayServer.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -16,33 +17,37 @@ namespace BTCPayServer.Migrations protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "8.0.1"); + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("BTCPayServer.Data.APIKeyData", b => { b.Property("Id") .HasMaxLength(50) - .HasColumnType("TEXT"); + .HasColumnType("character varying(50)"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Blob2") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("Label") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("StoreId") .HasMaxLength(50) - .HasColumnType("TEXT"); + .HasColumnType("character varying(50)"); b.Property("Type") - .HasColumnType("INTEGER"); + .HasColumnType("integer"); b.Property("UserId") .HasMaxLength(50) - .HasColumnType("TEXT"); + .HasColumnType("character varying(50)"); b.HasKey("Id"); @@ -56,13 +61,13 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.AddressInvoiceData", b => { b.Property("Address") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("CreatedTime") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("InvoiceDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Address"); @@ -74,28 +79,28 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.AppData", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("AppType") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Archived") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("Created") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("Name") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Settings") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("StoreDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("TagAllInvoices") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.HasKey("Id"); @@ -107,75 +112,75 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.ApplicationUser", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("AccessFailedCount") - .HasColumnType("INTEGER"); + .HasColumnType("integer"); b.Property("Approved") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Blob2") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Created") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("DisabledNotifications") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Email") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("EmailConfirmed") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("LockoutEnabled") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("LockoutEnd") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("NormalizedEmail") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("NormalizedUserName") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("PasswordHash") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("PhoneNumber") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("PhoneNumberConfirmed") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("RequiresApproval") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("RequiresEmailConfirmation") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("SecurityStamp") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("TwoFactorEnabled") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("UserName") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.HasKey("Id"); @@ -193,22 +198,22 @@ namespace BTCPayServer.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ApplicationUserId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Blob2") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("Name") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Type") - .HasColumnType("INTEGER"); + .HasColumnType("integer"); b.HasKey("Id"); @@ -221,19 +226,19 @@ namespace BTCPayServer.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Config") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("Name") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Public") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("StoreId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -245,48 +250,49 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.InvoiceData", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Amount") - .HasColumnType("TEXT"); + .HasColumnType("NUMERIC"); b.Property("Archived") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Blob2") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("Created") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("Currency") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("CustomerEmail") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ExceptionStatus") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ItemCode") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("OrderId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Status") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("StoreDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("XMin") .IsConcurrencyToken() .ValueGeneratedOnAddOrUpdate() - .HasColumnType("INTEGER"); + .HasColumnType("xid") + .HasColumnName("xmin"); b.HasKey("Id"); @@ -302,19 +308,19 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.InvoiceEventData", b => { b.Property("InvoiceDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("UniqueId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Message") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Severity") - .HasColumnType("INTEGER"); + .HasColumnType("integer"); b.Property("Timestamp") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.HasKey("InvoiceDataId", "UniqueId"); @@ -325,16 +331,17 @@ namespace BTCPayServer.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER") + .HasColumnType("integer") .HasAnnotation("MySql:ValueGeneratedOnAdd", true) - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) .HasAnnotation("Sqlite:Autoincrement", true); + NpgsqlPropertyBuilderExtensions.UseSerialColumn(b.Property("Id")); + b.Property("InvoiceDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Value") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -348,10 +355,10 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.InvoiceWebhookDeliveryData", b => { b.Property("InvoiceId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("DeliveryId") - .HasColumnType("TEXT"); + .HasColumnType("character varying(25)"); b.HasKey("InvoiceId", "DeliveryId"); @@ -367,17 +374,17 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.LightningAddressData", b => { b.Property("Username") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Blob2") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("StoreDataId") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Username"); @@ -390,29 +397,29 @@ namespace BTCPayServer.Migrations { b.Property("Id") .HasMaxLength(36) - .HasColumnType("TEXT"); + .HasColumnType("character varying(36)"); b.Property("ApplicationUserId") .IsRequired() .HasMaxLength(50) - .HasColumnType("TEXT"); + .HasColumnType("character varying(50)"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Blob2") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("Created") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("NotificationType") .IsRequired() .HasMaxLength(100) - .HasColumnType("TEXT"); + .HasColumnType("character varying(100)"); b.Property("Seen") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.HasKey("Id"); @@ -425,10 +432,10 @@ namespace BTCPayServer.Migrations { b.Property("Id") .HasMaxLength(64) - .HasColumnType("TEXT"); + .HasColumnType("character varying(64)"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.HasKey("Id"); @@ -438,19 +445,19 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.PairedSINData", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Label") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("PairingTime") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("SIN") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("StoreDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -464,28 +471,28 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.PairingCodeData", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("DateCreated") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("Expiration") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("Facade") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Label") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("SIN") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("StoreDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("TokenValue") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -496,7 +503,7 @@ namespace BTCPayServer.Migrations { b.Property("Id") .HasMaxLength(100) - .HasColumnType("TEXT"); + .HasColumnType("character varying(100)"); b.HasKey("Id"); @@ -506,34 +513,34 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.PaymentData", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); - b.Property("Accounted") - .HasColumnType("INTEGER"); + b.Property("Accounted") + .HasColumnType("boolean"); b.Property("Amount") - .HasColumnType("TEXT"); + .HasColumnType("NUMERIC"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Blob2") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("Created") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("Currency") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("InvoiceDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Status") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Type") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -545,27 +552,27 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.PaymentRequestData", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Archived") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Blob2") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("Created") .ValueGeneratedOnAdd() - .HasColumnType("TEXT") + .HasColumnType("timestamp with time zone") .HasDefaultValue(new DateTimeOffset(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0))); b.Property("Status") - .HasColumnType("INTEGER"); + .HasColumnType("integer"); b.Property("StoreDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -580,35 +587,35 @@ namespace BTCPayServer.Migrations { b.Property("Id") .HasMaxLength(30) - .HasColumnType("TEXT"); + .HasColumnType("character varying(30)"); b.Property("Blob") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("Date") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("Destination") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("PaymentMethodId") .IsRequired() .HasMaxLength(20) - .HasColumnType("TEXT"); + .HasColumnType("character varying(20)"); b.Property("Proof") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("PullPaymentDataId") - .HasColumnType("TEXT"); + .HasColumnType("character varying(30)"); b.Property("State") .IsRequired() .HasMaxLength(20) - .HasColumnType("TEXT"); + .HasColumnType("character varying(20)"); b.Property("StoreDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -627,22 +634,22 @@ namespace BTCPayServer.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Blob2") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("PaymentMethod") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Processor") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("StoreId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -654,7 +661,7 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.PendingInvoiceData", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -665,13 +672,13 @@ namespace BTCPayServer.Migrations { b.Property("Id") .HasMaxLength(100) - .HasColumnType("TEXT"); + .HasColumnType("character varying(100)"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("BroadcastAt") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.HasKey("Id"); @@ -682,26 +689,26 @@ namespace BTCPayServer.Migrations { b.Property("Id") .HasMaxLength(30) - .HasColumnType("TEXT"); + .HasColumnType("character varying(30)"); b.Property("Archived") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("Blob") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("EndDate") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("Period") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("StartDate") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("StoreId") .HasMaxLength(50) - .HasColumnType("TEXT"); + .HasColumnType("character varying(50)"); b.HasKey("Id"); @@ -713,11 +720,11 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.RefundData", b => { b.Property("InvoiceDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("PullPaymentDataId") .HasMaxLength(30) - .HasColumnType("TEXT"); + .HasColumnType("character varying(30)"); b.HasKey("InvoiceDataId", "PullPaymentDataId"); @@ -729,10 +736,10 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.SettingData", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Value") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.HasKey("Id"); @@ -742,34 +749,34 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.StoreData", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Archived") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("DefaultCrypto") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("DerivationStrategies") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("DerivationStrategy") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("SpeedPolicy") - .HasColumnType("INTEGER"); + .HasColumnType("integer"); b.Property("StoreBlob") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("StoreCertificate") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("StoreName") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("StoreWebsite") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -779,16 +786,16 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.StoreRole", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); - b.Property("Permissions") - .HasColumnType("TEXT"); + b.Property>("Permissions") + .HasColumnType("text[]"); b.Property("Role") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("StoreDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -801,13 +808,13 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.StoreSettingData", b => { b.Property("StoreId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Name") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Value") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.HasKey("StoreId", "Name"); @@ -817,10 +824,10 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.StoreWebhookData", b => { b.Property("StoreId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("WebhookId") - .HasColumnType("TEXT"); + .HasColumnType("character varying(25)"); b.HasKey("StoreId", "WebhookId"); @@ -837,19 +844,19 @@ namespace BTCPayServer.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ApplicationUserId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("FileName") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("StorageFileName") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Timestamp") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.HasKey("Id"); @@ -861,28 +868,28 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.U2FDevice", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ApplicationUserId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("AttestationCert") .IsRequired() - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Counter") - .HasColumnType("INTEGER"); + .HasColumnType("integer"); b.Property("KeyHandle") .IsRequired() - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Name") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("PublicKey") .IsRequired() - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.HasKey("Id"); @@ -894,13 +901,13 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.UserStore", b => { b.Property("ApplicationUserId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("StoreDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("StoreRoleId") - .HasColumnType("TEXT") + .HasColumnType("text") .HasColumnName("Role"); b.HasKey("ApplicationUserId", "StoreDataId"); @@ -915,10 +922,10 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.WalletData", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.HasKey("Id"); @@ -928,16 +935,16 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.WalletObjectData", b => { b.Property("WalletId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Type") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Data") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.HasKey("WalletId", "Type", "Id"); @@ -949,22 +956,22 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.WalletObjectLinkData", b => { b.Property("WalletId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("AType") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("AId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("BType") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("BId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Data") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.HasKey("WalletId", "AType", "AId", "BType", "BId"); @@ -976,16 +983,16 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("BTCPayServer.Data.WalletTransactionData", b => { b.Property("WalletDataId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("TransactionId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Labels") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("WalletDataId", "TransactionId"); @@ -996,13 +1003,13 @@ namespace BTCPayServer.Migrations { b.Property("Id") .HasMaxLength(25) - .HasColumnType("TEXT"); + .HasColumnType("character varying(25)"); b.Property("Blob") - .HasColumnType("BLOB"); + .HasColumnType("bytea"); b.Property("Blob2") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.HasKey("Id"); @@ -1013,21 +1020,21 @@ namespace BTCPayServer.Migrations { b.Property("Id") .HasMaxLength(25) - .HasColumnType("TEXT"); + .HasColumnType("character varying(25)"); b.Property("Blob") - .HasColumnType("TEXT"); + .HasColumnType("JSONB"); b.Property("Pruned") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("Timestamp") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("WebhookId") .IsRequired() .HasMaxLength(25) - .HasColumnType("TEXT"); + .HasColumnType("character varying(25)"); b.HasKey("Id"); @@ -1041,19 +1048,19 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Name") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("NormalizedName") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.HasKey("Id"); @@ -1068,17 +1075,19 @@ namespace BTCPayServer.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ClaimValue") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("RoleId") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -1091,17 +1100,19 @@ namespace BTCPayServer.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ClaimValue") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("UserId") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -1113,17 +1124,17 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ProviderKey") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ProviderDisplayName") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("UserId") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("LoginProvider", "ProviderKey"); @@ -1135,10 +1146,10 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("RoleId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("UserId", "RoleId"); @@ -1150,16 +1161,16 @@ namespace BTCPayServer.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("LoginProvider") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Name") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Value") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("UserId", "LoginProvider", "Name"); diff --git a/BTCPayServer.Data/MigrationsExtensions.cs b/BTCPayServer.Data/MigrationsExtensions.cs deleted file mode 100644 index e39a0af10..000000000 --- a/BTCPayServer.Data/MigrationsExtensions.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Microsoft.EntityFrameworkCore.Infrastructure; - -namespace BTCPayServer.Migrations -{ - public static class MigrationsExtensions - { - public static bool SupportDropColumn(this Microsoft.EntityFrameworkCore.Migrations.Migration migration, string activeProvider) - { - return activeProvider != "Microsoft.EntityFrameworkCore.Sqlite"; - } - public static bool SupportAddForeignKey(this Microsoft.EntityFrameworkCore.Migrations.Migration migration, string activeProvider) - { - return activeProvider != "Microsoft.EntityFrameworkCore.Sqlite"; - } - public static bool SupportDropForeignKey(this Microsoft.EntityFrameworkCore.Migrations.Migration migration, string activeProvider) - { - return activeProvider != "Microsoft.EntityFrameworkCore.Sqlite"; - } - public static bool SupportDropForeignKey(this DatabaseFacade facade) - { - return facade.ProviderName != "Microsoft.EntityFrameworkCore.Sqlite"; - } - public static bool IsMySql(this Microsoft.EntityFrameworkCore.Migrations.Migration migration, string activeProvider) - { - return activeProvider == "Pomelo.EntityFrameworkCore.MySql"; - } - } -} diff --git a/BTCPayServer.Tests/FastTests.cs b/BTCPayServer.Tests/FastTests.cs index 7a23b3f83..4536d270d 100644 --- a/BTCPayServer.Tests/FastTests.cs +++ b/BTCPayServer.Tests/FastTests.cs @@ -1270,17 +1270,6 @@ bc1qfzu57kgu5jthl934f9xrdzzx8mmemx7gn07tf0grnvz504j6kzusu2v0ku Assert.Contains("originalDeliveryId", serialized); } - [Fact] - public async Task CanCreateSqlitedb() - { - if (File.Exists("temp.db")) - File.Delete("temp.db"); - // This test sqlite can migrate - var builder = new DbContextOptionsBuilder(); - builder.UseSqlite("Data Source=temp.db"); - await new ApplicationDbContext(builder.Options).Database.MigrateAsync(); - } - [Fact] public void CanUsePermission() { diff --git a/BTCPayServer.Tests/GreenfieldAPITests.cs b/BTCPayServer.Tests/GreenfieldAPITests.cs index 2fb955963..8f9204c8e 100644 --- a/BTCPayServer.Tests/GreenfieldAPITests.cs +++ b/BTCPayServer.Tests/GreenfieldAPITests.cs @@ -4179,20 +4179,20 @@ namespace BTCPayServer.Tests Assert.Single(testObj.Links.Where(l => l.Id == "test1" && l.LinkData["testData"]?.Value() == "lol")); Assert.Single(testObj.Links.Where(l => l.Id == "test1" && l.ObjectData is null)); - async Task TestWalletRepository(bool useInefficient) + async Task TestWalletRepository() { // We should have 4 nodes, two `test` type and one `newtype` // Only the node `test` `test` is connected to `test1` var wid = new WalletId(admin.StoreId, "BTC"); var repo = tester.PayTester.GetService(); - var allObjects = await repo.GetWalletObjects(new(wid) { UseInefficientPath = useInefficient }); - var allObjectsNoWallet = await repo.GetWalletObjects((new() { UseInefficientPath = useInefficient })); - var allObjectsNoWalletAndType = await repo.GetWalletObjects((new() { Type = "test", UseInefficientPath = useInefficient })); - var allTests = await repo.GetWalletObjects((new(wid, "test") { UseInefficientPath = useInefficient })); - var twoTests2 = await repo.GetWalletObjects((new(wid, "test", new[] { "test1", "test2", "test-unk" }) { UseInefficientPath = useInefficient })); - var oneTest = await repo.GetWalletObjects((new(wid, "test", new[] { "test" }) { UseInefficientPath = useInefficient })); - var oneTestWithoutData = await repo.GetWalletObjects((new(wid, "test", new[] { "test" }) { UseInefficientPath = useInefficient, IncludeNeighbours = false })); - var idsTypes = await repo.GetWalletObjects((new(wid) { TypesIds = new[] { new ObjectTypeId("test", "test1"), new ObjectTypeId("test", "test2") }, UseInefficientPath = useInefficient })); + var allObjects = await repo.GetWalletObjects(new(wid)); + var allObjectsNoWallet = await repo.GetWalletObjects((new())); + var allObjectsNoWalletAndType = await repo.GetWalletObjects((new() { Type = "test" })); + var allTests = await repo.GetWalletObjects((new(wid, "test"))); + var twoTests2 = await repo.GetWalletObjects((new(wid, "test", new[] { "test1", "test2", "test-unk" }))); + var oneTest = await repo.GetWalletObjects((new(wid, "test", new[] { "test" }))); + var oneTestWithoutData = await repo.GetWalletObjects((new(wid, "test", new[] { "test" }) { IncludeNeighbours = false })); + var idsTypes = await repo.GetWalletObjects((new(wid) { TypesIds = new[] { new ObjectTypeId("test", "test1"), new ObjectTypeId("test", "test2") }})); Assert.Equal(4, allObjects.Count); // We are reusing a db in this test, as such we may have other wallets here. @@ -4206,8 +4206,7 @@ namespace BTCPayServer.Tests Assert.Null(oneTestWithoutData.First().Value.GetNeighbours().Select(n => n.Data).FirstOrDefault()); Assert.Equal(2, idsTypes.Count); } - await TestWalletRepository(false); - await TestWalletRepository(true); + await TestWalletRepository(); { var allObjects = await client.GetOnChainWalletObjects(admin.StoreId, "BTC"); diff --git a/BTCPayServer/Configuration/DefaultConfiguration.cs b/BTCPayServer/Configuration/DefaultConfiguration.cs index 0eb6381c5..f7bef2382 100644 --- a/BTCPayServer/Configuration/DefaultConfiguration.cs +++ b/BTCPayServer/Configuration/DefaultConfiguration.cs @@ -36,9 +36,7 @@ namespace BTCPayServer.Configuration app.Option("--signet | -signet", $"Use signet (deprecated, use --network instead)", CommandOptionType.BoolValue); app.Option("--chains | -c", $"Chains to support as a comma separated (default: btc; available: {chains})", CommandOptionType.SingleValue); app.Option("--postgres", $"Connection string to a PostgreSQL database", CommandOptionType.SingleValue); - app.Option("--mysql", $"DEPRECATED: Connection string to a MySQL database", CommandOptionType.SingleValue); app.Option("--nocsp", $"Disable CSP (default false)", CommandOptionType.BoolValue); - app.Option("--sqlitefile", $"DEPRECATED: File name to an SQLite database file inside the data directory", CommandOptionType.SingleValue); app.Option("--deprecated", $"Allow deprecated settings (default:false)", CommandOptionType.BoolValue); app.Option("--externalservices", $"Links added to external services inside Server Settings / Services under the format service1:path2;service2:path2.(default: empty)", CommandOptionType.SingleValue); app.Option("--rootpath", "The root path in the URL to access BTCPay (default: /)", CommandOptionType.SingleValue); @@ -139,8 +137,6 @@ namespace BTCPayServer.Configuration builder.AppendLine(); builder.AppendLine("### Database ###"); builder.AppendLine("#postgres=User ID=root;Password=myPassword;Host=localhost;Port=5432;Database=myDataBase;"); - builder.AppendLine("#mysql=User ID=root;Password=myPassword;Host=localhost;Port=3306;Database=myDataBase;"); - builder.AppendLine("#sqlitefile=sqlite.db"); builder.AppendLine(); builder.AppendLine("### NBXplorer settings ###"); foreach (var n in CreateBTCPayNetworkProvider(networkType).GetAll().OfType()) diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldStoresController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldStoresController.cs index fdc8698c8..c5a978724 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldStoresController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldStoresController.cs @@ -63,12 +63,6 @@ namespace BTCPayServer.Controllers.Greenfield { return StoreNotFound(); } - - if (!_storeRepository.CanDeleteStores()) - { - return this.CreateAPIError("unsupported", - "BTCPay Server is using a database server that does not allow you to remove stores."); - } await _storeRepository.RemoveStore(storeId, _userManager.GetUserId(User)); return Ok(); } diff --git a/BTCPayServer/Controllers/UIStoresController.Settings.cs b/BTCPayServer/Controllers/UIStoresController.Settings.cs index 51596993d..03f2f222e 100644 --- a/BTCPayServer/Controllers/UIStoresController.Settings.cs +++ b/BTCPayServer/Controllers/UIStoresController.Settings.cs @@ -40,8 +40,7 @@ public partial class UIStoresController InvoiceExpiration = (int)storeBlob.InvoiceExpiration.TotalMinutes, DefaultCurrency = storeBlob.DefaultCurrency, BOLT11Expiration = (long)storeBlob.RefundBOLT11Expiration.TotalDays, - Archived = store.Archived, - CanDelete = _storeRepo.CanDeleteStores() + Archived = store.Archived }; return View(vm); diff --git a/BTCPayServer/HostedServices/CleanupWebhookDeliveriesTask.cs b/BTCPayServer/HostedServices/CleanupWebhookDeliveriesTask.cs index 57d8e41a6..fb81ff1cc 100644 --- a/BTCPayServer/HostedServices/CleanupWebhookDeliveriesTask.cs +++ b/BTCPayServer/HostedServices/CleanupWebhookDeliveriesTask.cs @@ -24,8 +24,6 @@ namespace BTCPayServer.HostedServices public async Task Do(CancellationToken cancellationToken) { await using var ctx = DbContextFactory.CreateContext(); - if (!ctx.Database.IsNpgsql()) - return; var conn = ctx.Database.GetDbConnection(); bool pruned = false; int offset = 0; diff --git a/BTCPayServer/Hosting/BTCPayServerServices.cs b/BTCPayServer/Hosting/BTCPayServerServices.cs index addf609c4..d59560128 100644 --- a/BTCPayServer/Hosting/BTCPayServerServices.cs +++ b/BTCPayServer/Hosting/BTCPayServerServices.cs @@ -145,9 +145,7 @@ namespace BTCPayServer.Hosting services.TryAddSingleton(); services.TryAddSingleton(o => o.GetRequiredService>().Value); - // Don't move this StartupTask, we depend on it being right here - if (configuration["POSTGRES"] != null && (configuration["SQLITEFILE"] != null || configuration["MYSQL"] != null)) - services.AddStartupTask(); + services.AddStartupTask(); // @@ -184,24 +182,10 @@ namespace BTCPayServer.Hosting (options, datadirs) => { var postgresConnectionString = configuration["postgres"]; - var mySQLConnectionString = configuration["mysql"]; - var sqliteFileName = configuration["sqlitefile"]; - if (!string.IsNullOrEmpty(postgresConnectionString)) { - options.DatabaseType = DatabaseType.Postgres; options.ConnectionString = postgresConnectionString; } - else if (!string.IsNullOrEmpty(mySQLConnectionString)) - { - options.DatabaseType = DatabaseType.MySQL; - options.ConnectionString = mySQLConnectionString; - } - else if (!string.IsNullOrEmpty(sqliteFileName)) - { - options.DatabaseType = DatabaseType.Sqlite; - options.ConnectionString = "Data Source=" + datadirs.Value.ToDatadirFullPath(sqliteFileName); - } else { throw new InvalidOperationException("No database option was configured."); diff --git a/BTCPayServer/Hosting/MigrationStartupTask.cs b/BTCPayServer/Hosting/MigrationStartupTask.cs index e272cc0da..85aead4b8 100644 --- a/BTCPayServer/Hosting/MigrationStartupTask.cs +++ b/BTCPayServer/Hosting/MigrationStartupTask.cs @@ -372,12 +372,21 @@ namespace BTCPayServer.Hosting private async Task FixSeqAfterSqliteMigration() { await using var ctx = _DBContextFactory.CreateContext(); - if (!ctx.Database.IsNpgsql()) - return; - var state = await ToPostgresMigrationStartupTask.GetMigrationState(ctx); + var state = await GetMigrationState(ctx); if (state != "complete") return; - await ToPostgresMigrationStartupTask.UpdateSequenceInvoiceSearch(ctx); + 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; + if (o is null) + return null; + return JObject.Parse(o)["state"]?.Value(); + } + static async Task UpdateSequenceInvoiceSearch(ApplicationDbContext postgresContext) + { + await postgresContext.Database.ExecuteSqlRawAsync("SELECT SETVAL('\"InvoiceSearches_Id_seq\"', (SELECT max(\"Id\") FROM \"InvoiceSearches\"));"); } private async Task MigrateAppYmlToJson() { @@ -646,9 +655,7 @@ namespace BTCPayServer.Hosting { await using var ctx = _DBContextFactory.CreateContext(); - if (ctx.Database.IsNpgsql()) - { - await ctx.Database.ExecuteSqlRawAsync(@" + await ctx.Database.ExecuteSqlRawAsync(@" WITH cte AS ( SELECT DISTINCT p.""Id"", pp.""StoreId"" FROM ""Payouts"" p JOIN ""PullPayments"" pp ON pp.""Id"" = p.""PullPaymentDataId"" @@ -659,22 +666,6 @@ SET ""StoreDataId""=cte.""StoreId"" FROM cte WHERE cte.""Id""=p.""Id"" "); - } - else - { - var queryable = ctx.Payouts.Where(data => data.StoreDataId == null); - var count = await queryable.CountAsync(); - _logger.LogInformation($"Migrating {count} payouts to have a store id explicitly"); - for (int i = 0; i < count; i += 1000) - { - await queryable.Include(data => data.PullPaymentData).Skip(i).Take(1000) - .ForEachAsync(data => data.StoreDataId = data.PullPaymentData.StoreId); - - await ctx.SaveChangesAsync(); - - _logger.LogInformation($"Migrated {i + 1000}/{count} payouts to have a store id explicitly"); - } - } } private async Task AddInitialUserBlob() @@ -944,11 +935,6 @@ retry: { var db = _DBContextFactory.CreateContext(); await db.Database.MigrateAsync(); - if (db.Database.IsNpgsql()) - { - if (await db.GetMigrationState() == "pending") - throw new ConfigException("This database hasn't been completely migrated, please retry migration by setting the BTCPAY_SQLITEFILE or BTCPAY_MYSQL setting on top of BTCPAY_POSTGRES"); - } } // Starting up catch (ConfigException) { throw; } diff --git a/BTCPayServer/Hosting/ToPostgresMigrationStartupTask.cs b/BTCPayServer/Hosting/ToPostgresMigrationStartupTask.cs deleted file mode 100644 index 0e39371fc..000000000 --- a/BTCPayServer/Hosting/ToPostgresMigrationStartupTask.cs +++ /dev/null @@ -1,296 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using Amazon.Runtime.Internal.Util; -using AngleSharp.Text; -using BTCPayServer.Abstractions.Contracts; -using BTCPayServer.Configuration; -using BTCPayServer.Data; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Identity; -using Microsoft.Data.Sqlite; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Conventions; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using MySqlConnector; -using NBXplorer; -using Newtonsoft.Json.Linq; -using Npgsql; - -namespace BTCPayServer.Hosting -{ - static class TopologySort - { - public static IEnumerable OrderByTopology(this IEnumerable tables) - { - var comparer = Comparer.Create((a, b) => a.Name.CompareTo(b.Name)); - return OrderByTopology( - tables, - t => - { - if (t.Name == "Invoices") - return t.ForeignKeyConstraints.Select(f => f.PrincipalTable.Name).Where(f => f != "Refunds"); - else - return t.ForeignKeyConstraints.Select(f => f.PrincipalTable.Name); - }, - t => t.Name, - t => t, - comparer); - } - public static IEnumerable OrderByTopology( - this IEnumerable values, - Func> dependsOn, - Func getKey, - Func getValue, - IComparer? solveTies = null) where T : notnull - { - var v = values.ToList(); - return TopologicalSort(v, dependsOn, getKey, getValue, solveTies); - } - - static List TopologicalSort(this IReadOnlyCollection nodes, - Func> dependsOn, - Func getKey, - Func getValue, - IComparer? solveTies = null) where T : notnull - { - if (nodes.Count == 0) - return new List(); - if (getKey == null) - throw new ArgumentNullException(nameof(getKey)); - if (getValue == null) - throw new ArgumentNullException(nameof(getValue)); - solveTies = solveTies ?? Comparer.Default; - List result = new List(nodes.Count); - HashSet allKeys = new HashSet(nodes.Count); - var noDependencies = new SortedDictionary>(solveTies); - - foreach (var node in nodes) - allKeys.Add(getKey(node)); - var dependenciesByValues = nodes.ToDictionary(node => node, - node => new HashSet(dependsOn(node).Where(n => allKeys.Contains(n)))); - foreach (var e in dependenciesByValues.Where(x => x.Value.Count == 0)) - { - noDependencies.Add(e.Key, e.Value); - } - if (noDependencies.Count == 0) - { - throw new InvalidOperationException("Impossible to topologically sort a cyclic graph"); - } - while (noDependencies.Count > 0) - { - var nodep = noDependencies.First(); - noDependencies.Remove(nodep.Key); - dependenciesByValues.Remove(nodep.Key); - - var elemKey = getKey(nodep.Key); - result.Add(getValue(nodep.Key)); - foreach (var selem in dependenciesByValues) - { - if (selem.Value.Remove(elemKey) && selem.Value.Count == 0) - noDependencies.Add(selem.Key, selem.Value); - } - } - if (dependenciesByValues.Count != 0) - { - throw new InvalidOperationException("Impossible to topologically sort a cyclic graph"); - } - return result; - } - } - public class ToPostgresMigrationStartupTask : IStartupTask - { - - public ToPostgresMigrationStartupTask( - IConfiguration configuration, - IOptions datadirs, - ILogger logger, - IWebHostEnvironment environment, - ApplicationDbContextFactory dbContextFactory) - { - Configuration = configuration; - Datadirs = datadirs; - Logger = logger; - Environment = environment; - DbContextFactory = dbContextFactory; - } - - public IConfiguration Configuration { get; } - public IOptions Datadirs { get; } - public ILogger Logger { get; } - public IWebHostEnvironment Environment { get; } - public ApplicationDbContextFactory DbContextFactory { get; } - public bool HasError { get; private set; } - - public async Task ExecuteAsync(CancellationToken cancellationToken = default) - { - var p = Configuration.GetOrDefault("POSTGRES", null); - var sqlite = Configuration.GetOrDefault("SQLITEFILE", null); - var mysql = Configuration.GetOrDefault("MYSQL", null); - - string migratingFrom; - ApplicationDbContext otherContext; - if (string.IsNullOrEmpty(p)) - { - return; - } - else if (!string.IsNullOrEmpty(sqlite)) - { - migratingFrom = "SQLite"; - sqlite = Datadirs.Value.ToDatadirFullPath(sqlite); - if (!File.Exists(sqlite)) - return; - otherContext = new ApplicationDbContext(new DbContextOptionsBuilder().UseSqlite("Data Source=" + sqlite, o => o.CommandTimeout(60 * 60 * 10)).Options); - } - else if (!string.IsNullOrEmpty(mysql)) - { - migratingFrom = "MySQL"; - otherContext = new ApplicationDbContext(new DbContextOptionsBuilder().UseMySql(mysql, ServerVersion.AutoDetect(mysql), o => o.CommandTimeout(60 * 60 * 10)).Options); - try - { - await otherContext.Settings.FirstOrDefaultAsync(); - } - catch (MySqlException ex) when (ex.SqlState == "42000") // DB doesn't exists - { - return; - } - } - else - { - return; - } - if (await otherContext.Settings.FirstOrDefaultAsync() == null) - return; - { - using var postgresContext = new ApplicationDbContext(new DbContextOptionsBuilder().UseNpgsql(p, o => - { - o.CommandTimeout(60 * 60 * 10); - o.SetPostgresVersion(12, 0); - }).Options); - string? state; - try - { - state = await GetMigrationState(postgresContext); - if (state == "complete") - return; - if (state == null) - throw new ConfigException("This postgres database isn't created during a migration. Please use an empty database for postgres when migrating. If it's not a migration, remove --sqlitefile or --mysql settings."); - } - catch (NpgsqlException ex) when (ex.SqlState == PostgresErrorCodes.InvalidCatalogName || ex.SqlState == PostgresErrorCodes.UndefinedTable) // DB doesn't exists - { - await postgresContext.Database.MigrateAsync(); - state = "pending"; - await SetMigrationState(postgresContext, migratingFrom, "pending"); - } - - Logger.LogInformation($"Migrating from {migratingFrom} to Postgres..."); - if (state == "pending") - { - Logger.LogInformation($"There is a unfinished migration in postgres... dropping all tables"); - foreach (var t in postgresContext.Model.GetRelationalModel().Tables.OrderByTopology()) - { - await postgresContext.Database.ExecuteSqlRawAsync($"DROP TABLE IF EXISTS \"{t.Name}\" CASCADE"); - } - await postgresContext.Database.ExecuteSqlRawAsync($"DROP TABLE IF EXISTS \"__EFMigrationsHistory\" CASCADE"); - await postgresContext.Database.MigrateAsync(); - } - else - { - throw new ConfigException("This database isn't created during a migration. Please use an empty database for postgres when migrating."); - } - await otherContext.Database.MigrateAsync(); - - await SetMigrationState(postgresContext, migratingFrom, "pending"); - - foreach (var t in postgresContext.Model.GetRelationalModel().Tables.OrderByTopology()) - { - var typeMapping = t.EntityTypeMappings.Single(); - var query = (IQueryable)otherContext.GetType().GetMethod("Set", new Type[0])!.MakeGenericMethod(typeMapping.TypeBase.ClrType).Invoke(otherContext, null)!; - if (t.Name == "WebhookDeliveries" || - t.Name == "InvoiceWebhookDeliveries" || - t.Name == "StoreRoles") - continue; - Logger.LogInformation($"Migrating table: " + t.Name); - List datetimeProperties = new List(); - foreach (var col in t.Columns) - if (col.PropertyMappings.Single().Property.ClrType == typeof(DateTime)) - { - datetimeProperties.Add(col.PropertyMappings.Single().Property.PropertyInfo!); - } - List datetimeoffsetProperties = new List(); - foreach (var col in t.Columns) - if (col.PropertyMappings.Single().Property.ClrType == typeof(DateTimeOffset)) - { - datetimeoffsetProperties.Add(col.PropertyMappings.Single().Property.PropertyInfo!); - } - var rows = await query.ToListAsync(); - foreach (var row in rows) - { - foreach (var prop in datetimeProperties) - { - var v = (DateTime)prop.GetValue(row)!; - if (v.Kind == DateTimeKind.Unspecified) - { - v = new DateTime(v.Ticks, DateTimeKind.Utc); - prop.SetValue(row, v); - } - else if (v.Kind == DateTimeKind.Local) - { - prop.SetValue(row, v.ToUniversalTime()); - } - } - foreach (var prop in datetimeoffsetProperties) - { - var v = (DateTimeOffset)prop.GetValue(row)!; - if (v.Offset != TimeSpan.Zero) - { - prop.SetValue(row, v.ToOffset(TimeSpan.Zero)); - } - } - postgresContext.Entry(row).State = EntityState.Added; - } - await postgresContext.SaveChangesAsync(); - postgresContext.ChangeTracker.Clear(); - } - await postgresContext.SaveChangesAsync(); - postgresContext.ChangeTracker.Clear(); - await UpdateSequenceInvoiceSearch(postgresContext); - await SetMigrationState(postgresContext, migratingFrom, "complete"); - } - otherContext.Dispose(); - SqliteConnection.ClearAllPools(); - MySqlConnection.ClearAllPools(); - - Logger.LogInformation($"Migration to postgres from {migratingFrom} successful"); - } - - internal static async Task UpdateSequenceInvoiceSearch(ApplicationDbContext postgresContext) - { - await postgresContext.Database.ExecuteSqlRawAsync("SELECT SETVAL('\"InvoiceSearches_Id_seq\"', (SELECT max(\"Id\") FROM \"InvoiceSearches\"));"); - } - - internal static async Task GetMigrationState(ApplicationDbContext postgresContext) - { - var o = (await postgresContext.Settings.FromSqlRaw("SELECT \"Id\", \"Value\" FROM \"Settings\" WHERE \"Id\"='MigrationData'").AsNoTracking().FirstOrDefaultAsync())?.Value; - if (o is null) - return null; - return JObject.Parse(o)["state"]?.Value(); - } - private static async Task SetMigrationState(ApplicationDbContext postgresContext, string migratingFrom, string state) - { - await postgresContext.Database.ExecuteSqlRawAsync( - "INSERT INTO \"Settings\" VALUES ('MigrationData', @p0::JSONB) ON CONFLICT (\"Id\") DO UPDATE SET \"Value\"=@p0::JSONB", - new[] { $"{{ \"from\": \"{migratingFrom}\", \"state\": \"{state}\" }}" }); - } - } -} diff --git a/BTCPayServer/Models/StoreViewModels/GeneralSettingsViewModel.cs b/BTCPayServer/Models/StoreViewModels/GeneralSettingsViewModel.cs index 90a68c430..2b41e216e 100644 --- a/BTCPayServer/Models/StoreViewModels/GeneralSettingsViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/GeneralSettingsViewModel.cs @@ -33,8 +33,6 @@ namespace BTCPayServer.Models.StoreViewModels public IFormFile CssFile { get; set; } public string CssFileId { get; set; } - public bool CanDelete { get; set; } - public bool Archived { get; set; } [Display(Name = "Allow anyone to create invoice")] diff --git a/BTCPayServer/Services/Stores/StoreRepository.cs b/BTCPayServer/Services/Stores/StoreRepository.cs index f96b5cd32..751ea9b98 100644 --- a/BTCPayServer/Services/Stores/StoreRepository.cs +++ b/BTCPayServer/Services/Stores/StoreRepository.cs @@ -335,8 +335,6 @@ namespace BTCPayServer.Services.Stores public async Task CleanUnreachableStores() { await using var ctx = _ContextFactory.CreateContext(); - if (!ctx.Database.SupportDropForeignKey()) - return; var events = new List(); foreach (var store in await ctx.Stores.Include(data => data.UserStores) .ThenInclude(store => store.StoreRole).Where(s => @@ -368,17 +366,14 @@ namespace BTCPayServer.Services.Stores private async Task DeleteStoreIfOrphan(string storeId) { await using var ctx = _ContextFactory.CreateContext(); - if (ctx.Database.SupportDropForeignKey()) + if (!await ctx.UserStore.Where(u => u.StoreDataId == storeId && u.StoreRole.Permissions.Contains(Policies.CanModifyStoreSettings)).AnyAsync()) { - if (!await ctx.UserStore.Where(u => u.StoreDataId == storeId && u.StoreRole.Permissions.Contains(Policies.CanModifyStoreSettings)).AnyAsync()) + var store = await ctx.Stores.FindAsync(storeId); + if (store != null) { - var store = await ctx.Stores.FindAsync(storeId); - if (store != null) - { - ctx.Stores.Remove(store); - await ctx.SaveChangesAsync(); - _eventAggregator.Publish(new StoreRemovedEvent(store.Id)); - } + ctx.Stores.Remove(store); + await ctx.SaveChangesAsync(); + _eventAggregator.Publish(new StoreRemovedEvent(store.Id)); } } } @@ -559,8 +554,6 @@ namespace BTCPayServer.Services.Stores { int retry = 0; using var ctx = _ContextFactory.CreateContext(); - if (!ctx.Database.SupportDropForeignKey()) - return false; var store = await ctx.Stores.FindAsync(storeId); if (store == null) return false; @@ -641,12 +634,6 @@ retry: { return ex.InnerException is Npgsql.PostgresException postgres && postgres.SqlState == "40P01"; } - - public bool CanDeleteStores() - { - using var ctx = _ContextFactory.CreateContext(); - return ctx.Database.SupportDropForeignKey(); - } } public record StoreRoleId diff --git a/BTCPayServer/Services/WalletRepository.cs b/BTCPayServer/Services/WalletRepository.cs index 1ca22c155..12ebc487e 100644 --- a/BTCPayServer/Services/WalletRepository.cs +++ b/BTCPayServer/Services/WalletRepository.cs @@ -55,7 +55,6 @@ namespace BTCPayServer.Services public string? Type { get; set; } public string[]? Ids { get; set; } public bool IncludeNeighbours { get; set; } = true; - public bool UseInefficientPath { get; set; } public static IEnumerable Get(ReceivedCoin coin) { @@ -96,151 +95,118 @@ namespace BTCPayServer.Services // pg_stat_statements output, making it impossible to analyze the performance impact of this query. // On top of this, the entity version is doing 2 left join to satisfy the Include queries, resulting in n*m row returned for each transaction. // n being the number of children, m the number of parents. - if (ctx.Database.IsNpgsql() && !queryObject.UseInefficientPath) + var connection = ctx.Database.GetDbConnection(); + if (connection.State != System.Data.ConnectionState.Open) + await connection.OpenAsync(); + + string walletIdFilter = queryObject.WalletId is not null ? " AND wos.\"WalletId\"=@walletId" : ""; + string typeFilter = queryObject.Type is not null ? " AND wos.\"Type\"=@type" : ""; + var cmd = connection.CreateCommand(); + var selectWalletObjects = + queryObject.TypesIds is not null ? + $"SELECT wos.* FROM unnest(@ids, @types) t(i,t) JOIN \"WalletObjects\" wos ON true{walletIdFilter} AND wos.\"Type\"=t AND wos.\"Id\"=i" : + queryObject.Ids is null ? + $"SELECT wos.* FROM \"WalletObjects\" wos WHERE true{walletIdFilter}{typeFilter} " : + queryObject.Ids.Length == 1 ? + $"SELECT wos.* FROM \"WalletObjects\" wos WHERE true{walletIdFilter} AND wos.\"Type\"=@type AND wos.\"Id\"=@id" : + $"SELECT wos.* FROM unnest(@ids) t JOIN \"WalletObjects\" wos ON true{walletIdFilter} AND wos.\"Type\"=@type AND wos.\"Id\"=t"; + + var includeNeighbourSelect = queryObject.IncludeNeighbours ? ", wos2.\"Data\" AS \"Data2\"" : ""; + var includeNeighbourJoin = queryObject.IncludeNeighbours ? "LEFT JOIN \"WalletObjects\" wos2 ON wos.\"WalletId\"=wos2.\"WalletId\" AND wol.\"Type2\"=wos2.\"Type\" AND wol.\"Id2\"=wos2.\"Id\"" : ""; + var query = + $"SELECT wos.\"WalletId\", wos.\"Id\", wos.\"Type\", wos.\"Data\", wol.\"LinkData\", wol.\"Type2\", wol.\"Id2\"{includeNeighbourSelect} FROM ({selectWalletObjects}) wos " + + $"LEFT JOIN LATERAL ( " + + "SELECT \"AType\" AS \"Type2\", \"AId\" AS \"Id2\", \"Data\" AS \"LinkData\" FROM \"WalletObjectLinks\" WHERE \"WalletId\"=wos.\"WalletId\" AND \"BType\"=wos.\"Type\" AND \"BId\"=wos.\"Id\" " + + "UNION " + + "SELECT \"BType\" AS \"Type2\", \"BId\" AS \"Id2\", \"Data\" AS \"LinkData\" FROM \"WalletObjectLinks\" WHERE \"WalletId\"=wos.\"WalletId\" AND \"AType\"=wos.\"Type\" AND \"AId\"=wos.\"Id\"" + + $" ) wol ON true " + includeNeighbourJoin; + cmd.CommandText = query; + if (queryObject.WalletId is not null) { - var connection = ctx.Database.GetDbConnection(); - if (connection.State != System.Data.ConnectionState.Open) - await connection.OpenAsync(); - - string walletIdFilter = queryObject.WalletId is not null ? " AND wos.\"WalletId\"=@walletId" : ""; - string typeFilter = queryObject.Type is not null ? " AND wos.\"Type\"=@type" : ""; - var cmd = connection.CreateCommand(); - var selectWalletObjects = - queryObject.TypesIds is not null ? - $"SELECT wos.* FROM unnest(@ids, @types) t(i,t) JOIN \"WalletObjects\" wos ON true{walletIdFilter} AND wos.\"Type\"=t AND wos.\"Id\"=i" : - queryObject.Ids is null ? - $"SELECT wos.* FROM \"WalletObjects\" wos WHERE true{walletIdFilter}{typeFilter} " : - queryObject.Ids.Length == 1 ? - $"SELECT wos.* FROM \"WalletObjects\" wos WHERE true{walletIdFilter} AND wos.\"Type\"=@type AND wos.\"Id\"=@id" : - $"SELECT wos.* FROM unnest(@ids) t JOIN \"WalletObjects\" wos ON true{walletIdFilter} AND wos.\"Type\"=@type AND wos.\"Id\"=t"; - - var includeNeighbourSelect = queryObject.IncludeNeighbours ? ", wos2.\"Data\" AS \"Data2\"" : ""; - var includeNeighbourJoin = queryObject.IncludeNeighbours ? "LEFT JOIN \"WalletObjects\" wos2 ON wos.\"WalletId\"=wos2.\"WalletId\" AND wol.\"Type2\"=wos2.\"Type\" AND wol.\"Id2\"=wos2.\"Id\"" : ""; - var query = - $"SELECT wos.\"WalletId\", wos.\"Id\", wos.\"Type\", wos.\"Data\", wol.\"LinkData\", wol.\"Type2\", wol.\"Id2\"{includeNeighbourSelect} FROM ({selectWalletObjects}) wos " + - $"LEFT JOIN LATERAL ( " + - "SELECT \"AType\" AS \"Type2\", \"AId\" AS \"Id2\", \"Data\" AS \"LinkData\" FROM \"WalletObjectLinks\" WHERE \"WalletId\"=wos.\"WalletId\" AND \"BType\"=wos.\"Type\" AND \"BId\"=wos.\"Id\" " + - "UNION " + - "SELECT \"BType\" AS \"Type2\", \"BId\" AS \"Id2\", \"Data\" AS \"LinkData\" FROM \"WalletObjectLinks\" WHERE \"WalletId\"=wos.\"WalletId\" AND \"AType\"=wos.\"Type\" AND \"AId\"=wos.\"Id\"" + - $" ) wol ON true " + includeNeighbourJoin; - cmd.CommandText = query; - if (queryObject.WalletId is not null) - { - var walletIdParam = cmd.CreateParameter(); - walletIdParam.ParameterName = "walletId"; - walletIdParam.Value = queryObject.WalletId.ToString(); - walletIdParam.DbType = System.Data.DbType.String; - cmd.Parameters.Add(walletIdParam); - } - - if (queryObject.Type != null) - { - var typeParam = cmd.CreateParameter(); - typeParam.ParameterName = "type"; - typeParam.Value = queryObject.Type; - typeParam.DbType = System.Data.DbType.String; - cmd.Parameters.Add(typeParam); - } - - if (queryObject.TypesIds != null) - { - var typesParam = cmd.CreateParameter(); - typesParam.ParameterName = "types"; - typesParam.Value = queryObject.TypesIds.Select(t => t.Type).ToList(); - typesParam.DbType = System.Data.DbType.Object; - cmd.Parameters.Add(typesParam); - var idParam = cmd.CreateParameter(); - idParam.ParameterName = "ids"; - idParam.Value = queryObject.TypesIds.Select(t => t.Id).ToList(); - idParam.DbType = System.Data.DbType.Object; - cmd.Parameters.Add(idParam); - } - - if (queryObject.Ids != null) - { - if (queryObject.Ids.Length == 1) - { - var txIdParam = cmd.CreateParameter(); - txIdParam.ParameterName = "id"; - txIdParam.Value = queryObject.Ids[0]; - txIdParam.DbType = System.Data.DbType.String; - cmd.Parameters.Add(txIdParam); - } - else - { - var txIdsParam = cmd.CreateParameter(); - txIdsParam.ParameterName = "ids"; - txIdsParam.Value = queryObject.Ids.ToList(); - txIdsParam.DbType = System.Data.DbType.Object; - cmd.Parameters.Add(txIdsParam); - } - } - await using var reader = await cmd.ExecuteReaderAsync(); - var wosById = new Dictionary(); - while (await reader.ReadAsync()) - { - WalletObjectData wo = new WalletObjectData(); - wo.WalletId = (string)reader["WalletId"]; - wo.Type = (string)reader["Type"]; - wo.Id = (string)reader["Id"]; - var id = new WalletObjectId(WalletId.Parse(wo.WalletId), wo.Type, wo.Id); - wo.Data = reader["Data"] is DBNull ? null : (string)reader["Data"]; - if (wosById.TryGetValue(id, out var wo2)) - wo = wo2; - else - { - wosById.Add(id, wo); - wo.Bs = new List(); - } - if (reader["Type2"] is not DBNull) - { - var l = new WalletObjectLinkData() - { - BType = (string)reader["Type2"], - BId = (string)reader["Id2"], - Data = reader["LinkData"] is DBNull ? null : (string)reader["LinkData"] - }; - wo.Bs.Add(l); - l.B = new WalletObjectData() - { - Type = l.BType, - Id = l.BId, - Data = (!queryObject.IncludeNeighbours || reader["Data2"] is DBNull) ? null : (string)reader["Data2"] - }; - } - } - return wosById; + var walletIdParam = cmd.CreateParameter(); + walletIdParam.ParameterName = "walletId"; + walletIdParam.Value = queryObject.WalletId.ToString(); + walletIdParam.DbType = System.Data.DbType.String; + cmd.Parameters.Add(walletIdParam); } - else // Unefficient path + + if (queryObject.Type != null) { - IQueryable q; - if (queryObject.TypesIds is not null) + var typeParam = cmd.CreateParameter(); + typeParam.ParameterName = "type"; + typeParam.Value = queryObject.Type; + typeParam.DbType = System.Data.DbType.String; + cmd.Parameters.Add(typeParam); + } + + if (queryObject.TypesIds != null) + { + var typesParam = cmd.CreateParameter(); + typesParam.ParameterName = "types"; + typesParam.Value = queryObject.TypesIds.Select(t => t.Type).ToList(); + typesParam.DbType = System.Data.DbType.Object; + cmd.Parameters.Add(typesParam); + var idParam = cmd.CreateParameter(); + idParam.ParameterName = "ids"; + idParam.Value = queryObject.TypesIds.Select(t => t.Id).ToList(); + idParam.DbType = System.Data.DbType.Object; + cmd.Parameters.Add(idParam); + } + + if (queryObject.Ids != null) + { + if (queryObject.Ids.Length == 1) { - // Note this is problematic if the type contains '##', but I don't see how to do it properly with entity framework - var idTypes = queryObject.TypesIds.Select(o => $"{o.Type}##{o.Id}").ToArray(); - q = ctx.WalletObjects - .Where(w => (queryObject.WalletId == null || w.WalletId == queryObject.WalletId.ToString()) && idTypes.Contains(w.Type + "##" + w.Id)); + var txIdParam = cmd.CreateParameter(); + txIdParam.ParameterName = "id"; + txIdParam.Value = queryObject.Ids[0]; + txIdParam.DbType = System.Data.DbType.String; + cmd.Parameters.Add(txIdParam); } else { - q = ctx.WalletObjects - .Where(w => (queryObject.WalletId == null || w.WalletId == queryObject.WalletId.ToString()) && (queryObject.Type == null || w.Type == queryObject.Type) && (queryObject.Ids == null || queryObject.Ids.Contains(w.Id))); + var txIdsParam = cmd.CreateParameter(); + txIdsParam.ParameterName = "ids"; + txIdsParam.Value = queryObject.Ids.ToList(); + txIdsParam.DbType = System.Data.DbType.Object; + cmd.Parameters.Add(txIdsParam); } - if (queryObject.IncludeNeighbours) - { - q = q.Include(o => o.Bs).ThenInclude(o => o.B) - .Include(o => o.As).ThenInclude(o => o.A); - } - q = q.AsNoTracking(); - - var wosById = new Dictionary(); - foreach (var row in await q.ToListAsync()) - { - var id = new WalletObjectId(WalletId.Parse(row.WalletId), row.Type, row.Id); - wosById.TryAdd(id, row); - } - return wosById; } + await using var reader = await cmd.ExecuteReaderAsync(); + var wosById = new Dictionary(); + while (await reader.ReadAsync()) + { + WalletObjectData wo = new WalletObjectData(); + wo.WalletId = (string)reader["WalletId"]; + wo.Type = (string)reader["Type"]; + wo.Id = (string)reader["Id"]; + var id = new WalletObjectId(WalletId.Parse(wo.WalletId), wo.Type, wo.Id); + wo.Data = reader["Data"] is DBNull ? null : (string)reader["Data"]; + if (wosById.TryGetValue(id, out var wo2)) + wo = wo2; + else + { + wosById.Add(id, wo); + wo.Bs = new List(); + } + if (reader["Type2"] is not DBNull) + { + var l = new WalletObjectLinkData() + { + BType = (string)reader["Type2"], + BId = (string)reader["Id2"], + Data = reader["LinkData"] is DBNull ? null : (string)reader["LinkData"] + }; + wo.Bs.Add(l); + l.B = new WalletObjectData() + { + Type = l.BType, + Id = l.BId, + Data = (!queryObject.IncludeNeighbours || reader["Data2"] is DBNull) ? null : (string)reader["Data2"] + }; + } + } + return wosById; } #nullable restore diff --git a/BTCPayServer/Views/UIStores/GeneralSettings.cshtml b/BTCPayServer/Views/UIStores/GeneralSettings.cshtml index 3f1878a84..878122084 100644 --- a/BTCPayServer/Views/UIStores/GeneralSettings.cshtml +++ b/BTCPayServer/Views/UIStores/GeneralSettings.cshtml @@ -176,10 +176,7 @@ } - @if (Model.CanDelete) - { - Delete this store - } + Delete this store