Migrations: Use reliable GUID to check for existence of data type when creating (#20604)

* Use reliable GUID to check for existence of data type in migration.

* Retrieve just a single field in existence check.
This commit is contained in:
Andy Butland
2025-10-22 12:21:42 +02:00
committed by GitHub
parent 79639c0571
commit 48759b9852

View File

@@ -6,7 +6,9 @@ using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus; using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Infrastructure.Persistence.Dtos;
using Umbraco.Extensions;
namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_16_3_0; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_16_3_0;
@@ -69,7 +71,7 @@ public class MigrateMediaTypeLabelProperties : AsyncMigrationBase
private void IfNotExistsCreateBytesLabel() private void IfNotExistsCreateBytesLabel()
{ {
if (Database.Exists<NodeDto>(Constants.DataTypes.LabelBytes)) if (NodeExists(_labelBytesDataTypeKey))
{ {
return; return;
} }
@@ -89,7 +91,7 @@ public class MigrateMediaTypeLabelProperties : AsyncMigrationBase
CreateDate = DateTime.Now, 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 var dataTypeDto = new DataTypeDto
{ {
@@ -100,12 +102,12 @@ public class MigrateMediaTypeLabelProperties : AsyncMigrationBase
Configuration = "{\"umbracoDataValueType\":\"BIGINT\", \"labelTemplate\":\"{=value | bytes}\"}", 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() private void IfNotExistsCreatePixelsLabel()
{ {
if (Database.Exists<NodeDto>(Constants.DataTypes.LabelPixels)) if (NodeExists(_labelPixelsDataTypeKey))
{ {
return; return;
} }
@@ -125,7 +127,7 @@ public class MigrateMediaTypeLabelProperties : AsyncMigrationBase
CreateDate = DateTime.Now, 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 var dataTypeDto = new DataTypeDto
{ {
@@ -136,7 +138,16 @@ public class MigrateMediaTypeLabelProperties : AsyncMigrationBase
Configuration = "{\"umbracoDataValueType\":\"INT\", \"labelTemplate\":\"{=value}px\"}", 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<ISqlContext> sql = Database.SqlContext.Sql()
.Select<NodeDto>(x => x.NodeId)
.From<NodeDto>()
.Where<NodeDto>(x => x.UniqueId == uniqueId);
return Database.FirstOrDefault<NodeDto>(sql) is not null;
} }
private async Task MigrateMediaTypeLabels() private async Task MigrateMediaTypeLabels()