Alter the datatype of the UmbracoKeyValue value column (#14085)
This commit is contained in:
@@ -67,5 +67,8 @@ public class UmbracoPlan : MigrationPlan
|
||||
|
||||
// To 11.3.0
|
||||
To<V_11_3_0.AddDomainSortOrder>("{BB3889ED-E2DE-49F2-8F71-5FD8616A2661}");
|
||||
|
||||
// To 11.4.0
|
||||
To<V_11_4_0.AlterKeyValueDataType>("{FFB6B9B0-F1A8-45E9-9CD7-25700577D1CA}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Reflection;
|
||||
using NPoco;
|
||||
using Umbraco.Cms.Infrastructure.Persistence;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_11_4_0;
|
||||
|
||||
public class AlterKeyValueDataType : MigrationBase
|
||||
{
|
||||
private readonly IMigrationContext _context;
|
||||
|
||||
public AlterKeyValueDataType(IMigrationContext context)
|
||||
: base(context) => _context = context;
|
||||
|
||||
protected override void Migrate()
|
||||
{
|
||||
// SQLite doesn't need this upgrade
|
||||
if (_context.Database.DatabaseType.IsSqlite())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string tableName = KeyValueDto.TableName;
|
||||
string colName = "value";
|
||||
|
||||
// Determine the current datatype of the column within the database
|
||||
string colDataType = Database.ExecuteScalar<string>($"SELECT TOP(1) CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS" +
|
||||
$" WHERE TABLE_NAME = '{tableName}' AND COLUMN_NAME = '{colName}'");
|
||||
|
||||
// 255 is the old length, -1 indicate MAX length
|
||||
if (colDataType == "255")
|
||||
{
|
||||
// Upgrade to MAX length
|
||||
Database.Execute($"ALTER TABLE {tableName} ALTER COLUMN {colName} nvarchar(MAX)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,15 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
||||
[ExplicitColumns]
|
||||
internal class KeyValueDto
|
||||
{
|
||||
public const string TableName = Constants.DatabaseSchema.Tables.KeyValue;
|
||||
|
||||
[Column("key")]
|
||||
[Length(256)]
|
||||
[PrimaryKeyColumn(AutoIncrement = false, Clustered = true)]
|
||||
public string Key { get; set; } = null!;
|
||||
|
||||
[Column("value")]
|
||||
[SpecialDbType(SpecialDbTypes.NVARCHARMAX)]
|
||||
[NullSetting(NullSetting = NullSettings.Null)]
|
||||
public string? Value { get; set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user