diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_16_3_0/MigrateMediaTypeLabelProperties.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_16_3_0/MigrateMediaTypeLabelProperties.cs index 3ced4a2a6a..efa48f00f2 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_16_3_0/MigrateMediaTypeLabelProperties.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_16_3_0/MigrateMediaTypeLabelProperties.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using NPoco; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Models; @@ -44,11 +45,28 @@ public class MigrateMediaTypeLabelProperties : AsyncMigrationBase return; } - IfNotExistsCreateBytesLabel(); - IfNotExistsCreatePixelsLabel(); + ToggleIndentityInsertForNodes(true); + try + { + IfNotExistsCreateBytesLabel(); + IfNotExistsCreatePixelsLabel(); + } + finally + { + ToggleIndentityInsertForNodes(false); + } + await MigrateMediaTypeLabels(); } + private void ToggleIndentityInsertForNodes(bool toggleOn) + { + if (SqlSyntax.SupportsIdentityInsert()) + { + Database.Execute(new Sql($"SET IDENTITY_INSERT {SqlSyntax.GetQuotedTableName(NodeDto.TableName)} {(toggleOn ? "ON" : "OFF")} ")); + } + } + private void IfNotExistsCreateBytesLabel() { if (Database.Exists(Constants.DataTypes.LabelBytes))