From b9b92a7ed47d25dc105d9813d8fa397af1e000d0 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 22 Oct 2025 11:31:13 +0200 Subject: [PATCH 1/2] Use reliable GUID to check for existence of data type in migration. --- .../MigrateMediaTypeLabelProperties.cs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) 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 efa48f00f276..f085be418e1f 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 @@ -6,7 +6,9 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Services.OperationStatus; +using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Dtos; +using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_16_3_0; @@ -69,7 +71,7 @@ private void ToggleIndentityInsertForNodes(bool toggleOn) private void IfNotExistsCreateBytesLabel() { - if (Database.Exists(Constants.DataTypes.LabelBytes)) + if (NodeExists(_labelBytesDataTypeKey)) { return; } @@ -89,7 +91,7 @@ private void IfNotExistsCreateBytesLabel() CreateDate = DateTime.Now, }; - _ = Database.Insert(Constants.DatabaseSchema.Tables.Node, "id", false, nodeDto); + Database.Insert(Constants.DatabaseSchema.Tables.Node, "id", false, nodeDto); var dataTypeDto = new DataTypeDto { @@ -100,12 +102,12 @@ private void IfNotExistsCreateBytesLabel() Configuration = "{\"umbracoDataValueType\":\"BIGINT\", \"labelTemplate\":\"{=value | bytes}\"}", }; - _ = Database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, dataTypeDto); + Database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, dataTypeDto); } private void IfNotExistsCreatePixelsLabel() { - if (Database.Exists(Constants.DataTypes.LabelPixels)) + if (NodeExists(_labelPixelsDataTypeKey)) { return; } @@ -125,7 +127,7 @@ private void IfNotExistsCreatePixelsLabel() CreateDate = DateTime.Now, }; - _ = Database.Insert(Constants.DatabaseSchema.Tables.Node, "id", false, nodeDto); + Database.Insert(Constants.DatabaseSchema.Tables.Node, "id", false, nodeDto); var dataTypeDto = new DataTypeDto { @@ -136,7 +138,16 @@ private void IfNotExistsCreatePixelsLabel() Configuration = "{\"umbracoDataValueType\":\"INT\", \"labelTemplate\":\"{=value}px\"}", }; - _ = Database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, dataTypeDto); + Database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, dataTypeDto); + } + + private bool NodeExists(Guid uniqueId) + { + Sql sql = Database.SqlContext.Sql() + .Select() + .From() + .Where(x => x.UniqueId == uniqueId); + return Database.FirstOrDefault(sql) is not null; } private async Task MigrateMediaTypeLabels() From 25e7608bbcca30fdd94f016c6cb53872964ba769 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 22 Oct 2025 11:43:02 +0200 Subject: [PATCH 2/2] Retrieve just a single field in existence check. --- .../Upgrade/V_16_3_0/MigrateMediaTypeLabelProperties.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f085be418e1f..71c824f35758 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 @@ -144,7 +144,7 @@ private void IfNotExistsCreatePixelsLabel() private bool NodeExists(Guid uniqueId) { Sql sql = Database.SqlContext.Sql() - .Select() + .Select(x => x.NodeId) .From() .Where(x => x.UniqueId == uniqueId); return Database.FirstOrDefault(sql) is not null;