diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs index 3ba30b12df29..2d6d47e645dd 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs @@ -106,5 +106,6 @@ protected virtual void DefinePlan() To("{21C42760-5109-4C03-AB4F-7EA53577D1F5}"); To("{6158F3A3-4902-4201-835E-1ED7F810B2D8}"); To("{985AF2BA-69D3-4DBA-95E0-AD3FA7459FA7}"); + To("{CC47C751-A81B-489A-A2BC-0240245DB687}"); } } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_13_5_0/ChangeRedirectUrlToNvarcharMax.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_13_5_0/ChangeRedirectUrlToNvarcharMax.cs new file mode 100644 index 000000000000..4f28b0fe8870 --- /dev/null +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_13_5_0/ChangeRedirectUrlToNvarcharMax.cs @@ -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($"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)"); + } + } +} diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/RedirectUrlDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/RedirectUrlDto.cs index 453ab1e308a2..3582a7eee569 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/RedirectUrlDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/RedirectUrlDto.cs @@ -38,6 +38,7 @@ internal class RedirectUrlDto [Column("url")] [NullSetting(NullSetting = NullSettings.NotNull)] + [SpecialDbType(SpecialDbTypes.NVARCHARMAX)] public string Url { get; set; } = null!; [Column("culture")]