Expand RedirectUrl.Url storage type to avoid truncation (#17038)
* Add migration to expand RedirectUrl.Url to varcharMax * Simplify Migration * readded notnull attribute
This commit is contained in:
@@ -106,5 +106,6 @@ public class UmbracoPlan : MigrationPlan
|
||||
To<V_13_0_0.ChangeWebhookUrlColumnsToNvarcharMax>("{21C42760-5109-4C03-AB4F-7EA53577D1F5}");
|
||||
To<V_13_0_0.AddExceptionOccured>("{6158F3A3-4902-4201-835E-1ED7F810B2D8}");
|
||||
To<V_13_3_0.AlignUpgradedDatabase>("{985AF2BA-69D3-4DBA-95E0-AD3FA7459FA7}");
|
||||
To<V_13_5_0.ChangeRedirectUrlToNvarcharMax>("{CC47C751-A81B-489A-A2BC-0240245DB687}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using NPoco;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Expressions.Create.Column;
|
||||
using Umbraco.Cms.Infrastructure.Persistence;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_13_5_0;
|
||||
|
||||
public class ChangeRedirectUrlToNvarcharMax : MigrationBase
|
||||
{
|
||||
public ChangeRedirectUrlToNvarcharMax(IMigrationContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Migrate()
|
||||
{
|
||||
// We don't need to run this migration for SQLite, since ntext is not a thing there, text is just text.
|
||||
if (DatabaseType == DatabaseType.SQLite)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string tableName = RedirectUrlDto.TableName;
|
||||
string colName = "url";
|
||||
|
||||
// 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($"Drop Index IX_umbracoRedirectUrl_culture_hash on {Constants.DatabaseSchema.Tables.RedirectUrl}");
|
||||
Database.Execute($"ALTER TABLE {tableName} ALTER COLUMN {colName} nvarchar(MAX) NOT NULL");
|
||||
Database.Execute($"CREATE INDEX IX_umbracoRedirectUrl_culture_hash ON {Constants.DatabaseSchema.Tables.RedirectUrl} (urlHash, contentKey, culture, createDateUtc)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ internal class RedirectUrlDto
|
||||
|
||||
[Column("url")]
|
||||
[NullSetting(NullSetting = NullSettings.NotNull)]
|
||||
[SpecialDbType(SpecialDbTypes.NVARCHARMAX)]
|
||||
public string Url { get; set; } = null!;
|
||||
|
||||
[Column("culture")]
|
||||
|
||||
Reference in New Issue
Block a user