diff --git a/BTCPayServer.Data/Data/StoreData.cs b/BTCPayServer.Data/Data/StoreData.cs index 002410f5d..02182d142 100644 --- a/BTCPayServer.Data/Data/StoreData.cs +++ b/BTCPayServer.Data/Data/StoreData.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; +using System.Text; using BTCPayServer.Client.Models; using BTCPayServer.Data.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using PayoutProcessorData = BTCPayServer.Data.Data.PayoutProcessorData; namespace BTCPayServer.Data @@ -62,6 +64,16 @@ namespace BTCPayServer.Data .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) + )); + } } } } diff --git a/BTCPayServer.Data/Migrations/20220311135252_AddPayoutProcessors.cs b/BTCPayServer.Data/Migrations/20220311135252_AddPayoutProcessors.cs index c6b393be0..37deb5ec8 100644 --- a/BTCPayServer.Data/Migrations/20220311135252_AddPayoutProcessors.cs +++ b/BTCPayServer.Data/Migrations/20220311135252_AddPayoutProcessors.cs @@ -1,4 +1,4 @@ -// +// using System; using BTCPayServer.Data; using Microsoft.EntityFrameworkCore; @@ -17,20 +17,21 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { + int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; migrationBuilder.AddColumn( name: "StoreDataId", table: "Payouts", - type: "TEXT", - nullable: true); + nullable: true, + maxLength: maxLength); migrationBuilder.CreateTable( name: "PayoutProcessors", columns: table => new { - Id = table.Column(type: "TEXT", nullable: false), - StoreId = table.Column(type: "TEXT", nullable: true), - PaymentMethod = table.Column(type: "TEXT", nullable: true), - Processor = table.Column(type: "TEXT", nullable: true), + Id = table.Column(nullable: false, maxLength: maxLength), + StoreId = table.Column(nullable: true, maxLength: maxLength), + PaymentMethod = table.Column(nullable: true), + Processor = table.Column(nullable: true), Blob = table.Column(nullable: true) }, constraints: table => diff --git a/BTCPayServer.Data/Migrations/20220414132313_AddLightningAddress.cs b/BTCPayServer.Data/Migrations/20220414132313_AddLightningAddress.cs index a5ca9b8e8..7fc81525e 100644 --- a/BTCPayServer.Data/Migrations/20220414132313_AddLightningAddress.cs +++ b/BTCPayServer.Data/Migrations/20220414132313_AddLightningAddress.cs @@ -1,4 +1,4 @@ -// +// using System; using BTCPayServer.Data; using Microsoft.EntityFrameworkCore; @@ -17,12 +17,13 @@ namespace BTCPayServer.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { + int? maxLength = this.IsMySql(migrationBuilder.ActiveProvider) ? (int?)255 : null; migrationBuilder.CreateTable( name: "LightningAddresses", columns: table => new { - Username = table.Column(type: "TEXT", nullable: false), - StoreDataId = table.Column(type: "TEXT", nullable: false), + Username = table.Column(nullable: false, maxLength: maxLength), + StoreDataId = table.Column(nullable: false, maxLength: maxLength), Blob = table.Column( nullable: true) }, constraints: table => diff --git a/BTCPayServer.Data/Migrations/20220610090843_AddSettingsToStore.cs b/BTCPayServer.Data/Migrations/20220610090843_AddSettingsToStore.cs index be69aed6c..bfebcf0ba 100644 --- a/BTCPayServer.Data/Migrations/20220610090843_AddSettingsToStore.cs +++ b/BTCPayServer.Data/Migrations/20220610090843_AddSettingsToStore.cs @@ -14,12 +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(type: "TEXT", nullable: false), - StoreId = table.Column(type: "TEXT", nullable: false), + Name = table.Column(nullable: false, maxLength: maxlength), + StoreId = table.Column(nullable: false, maxLength: maxlength), Value = table.Column(type: migrationBuilder.IsNpgsql() ? "JSONB" : "TEXT", nullable: true) }, constraints: table => diff --git a/BTCPayServer.Data/Migrations/20220929132704_label.cs b/BTCPayServer.Data/Migrations/20220929132704_label.cs index 0cb665e2f..7a167329d 100644 --- a/BTCPayServer.Data/Migrations/20220929132704_label.cs +++ b/BTCPayServer.Data/Migrations/20220929132704_label.cs @@ -17,13 +17,15 @@ 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(type: "TEXT", nullable: false), - Type = table.Column(type: "TEXT", nullable: false), - Id = table.Column(type: "TEXT", nullable: false), + 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) }, constraints: table => @@ -35,15 +37,17 @@ namespace BTCPayServer.Migrations table: "WalletObjects", columns: new[] { "Type", "Id" }); + + maxlength = migrationBuilder.IsMySql() ? 100 : null; migrationBuilder.CreateTable( name: "WalletObjectLinks", columns: table => new { - WalletId = table.Column(type: "TEXT", nullable: false), - AType = table.Column(type: "TEXT", nullable: false), - AId = table.Column(type: "TEXT", nullable: false), - BType = table.Column(type: "TEXT", nullable: false), - BId = table.Column(type: "TEXT", nullable: false), + 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) }, constraints: table =>