Add test for populating alias in migration
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
@@ -14,9 +15,21 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_17_0
|
||||
{
|
||||
AddColumn<PropertyTypeGroupDto>("type");
|
||||
|
||||
// Add column without constraints
|
||||
AddColumn<PropertyTypeGroupDto>("alias", out var sqls);
|
||||
|
||||
// Populate non-null alias column
|
||||
var dtos = Database.Fetch<PropertyTypeGroupDto>();
|
||||
foreach (var dto in PopulateAliases(dtos))
|
||||
Database.Update(dto, x => new { x.Alias });
|
||||
|
||||
// Finally add the constraints
|
||||
foreach (var sql in sqls)
|
||||
Database.Execute(sql);
|
||||
}
|
||||
|
||||
internal IEnumerable<PropertyTypeGroupDto> PopulateAliases(IEnumerable<PropertyTypeGroupDto> dtos)
|
||||
{
|
||||
foreach (var dtosPerAlias in dtos.GroupBy(x => x.Text.ToSafeAlias(true)))
|
||||
{
|
||||
var dtosPerAliasAndText = dtosPerAlias.GroupBy(x => x.Text);
|
||||
@@ -33,7 +46,7 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_17_0
|
||||
dto.Alias += numberSuffix;
|
||||
}
|
||||
|
||||
Database.Update(dto, x => new { x.Alias });
|
||||
yield return dto;
|
||||
}
|
||||
|
||||
numberSuffix++;
|
||||
@@ -44,9 +57,6 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_17_0
|
||||
Logger.Error<AddPropertyTypeGroupColumns>("Detected the same alias {Alias} for different property group names {Names}, the migration added suffixes, but this might break backwards compatibility.", dtosPerAlias.Key, dtosPerAliasAndText.Select(x => x.Key));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var sql in sqls)
|
||||
Database.Execute(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user