Add queue hardening by modifying DeploymentJobTargets, DeploymentJobSteps, and DeploymentJobs tables

- Drop existing indexes on DeploymentJobTargets and DeploymentJobSteps
- Alter Status column to nvarchar(450) in DeploymentJobTargets, DeploymentJobSteps, and DeploymentJobs
- Add new columns: Finished, OutputMetadataJson, Started to DeploymentJobTargets; ErrorMessage, Finished, OutputMetadataJson, Started to DeploymentJobSteps; CorrelationId, HeartbeatAt, Priority, RowVersion, ScheduledAt, WorkerName to DeploymentJobs
- Create new indexes for improved query performance
- Add constraints to ensure OutputMetadataJson is valid JSON
- Record migration in __EFMigrationsHistory
This commit is contained in:
Torsten Brendgen
2026-07-09 08:50:09 +02:00
parent 97238c28c9
commit 01c2a5df2e
45 changed files with 8198 additions and 75 deletions

View File

@@ -3,7 +3,7 @@ using Microsoft.SelfService.Portal.Core.API.Models;
namespace Microsoft.SelfService.Portal.Core.API.Context
{
internal static class DemoData
internal static partial class DemoData
{
private static readonly DateTime Timestamp = new(2026, 7, 7, 0, 0, 0, DateTimeKind.Utc);
private const string Owner = "DemoSeed";
@@ -22,16 +22,21 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
internal static readonly Guid VmSp02Id = Guid.Parse("30000000-0000-0000-0000-000000000005");
internal static readonly Guid TargetM365TenantId = Guid.Parse("30000000-0000-0000-0000-000000000006");
internal static readonly Guid TargetTeamsPolicyScopeId = Guid.Parse("30000000-0000-0000-0000-000000000007");
internal static readonly Guid TargetBgwSp01Id = Guid.Parse("30000000-0000-0000-0000-000000000101");
internal static readonly Guid TargetBgwSp02Id = Guid.Parse("30000000-0000-0000-0000-000000000102");
internal static readonly Guid TargetBgwSp03Id = Guid.Parse("30000000-0000-0000-0000-000000000103");
internal static readonly Guid ServiceActiveDirectoryId = Guid.Parse("40000000-0000-0000-0000-000000000001");
internal static readonly Guid ServiceSqlServerId = Guid.Parse("40000000-0000-0000-0000-000000000002");
internal static readonly Guid ServiceSharePointId = Guid.Parse("40000000-0000-0000-0000-000000000003");
internal static readonly Guid ServiceTeamsId = Guid.Parse("40000000-0000-0000-0000-000000000004");
internal static readonly Guid ServiceConfigurationDataId = Guid.Parse("40000000-0000-0000-0000-000000000101");
internal static readonly Guid CategoryActiveDirectoryId = Guid.Parse("50000000-0000-0000-0000-000000000001");
internal static readonly Guid CategorySqlServerId = Guid.Parse("50000000-0000-0000-0000-000000000002");
internal static readonly Guid CategorySharePointId = Guid.Parse("50000000-0000-0000-0000-000000000003");
internal static readonly Guid CategoryTeamsId = Guid.Parse("50000000-0000-0000-0000-000000000004");
internal static readonly Guid CategoryBgwMergeTemplatesId = Guid.Parse("50000000-0000-0000-0000-000000000101");
internal static readonly Guid RuleStandardId = Guid.Parse("60000000-0000-0000-0000-000000000001");
internal static readonly Guid RuleStepValidateId = Guid.Parse("60000000-0000-0000-0000-000000000101");
@@ -42,20 +47,39 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
internal static readonly Guid TemplateSqlServerId = Guid.Parse("70000000-0000-0000-0000-000000000002");
internal static readonly Guid TemplateSharePointId = Guid.Parse("70000000-0000-0000-0000-000000000003");
internal static readonly Guid TemplateTeamsId = Guid.Parse("70000000-0000-0000-0000-000000000004");
internal static readonly Guid TemplateBgwEnvironmentTestId = Guid.Parse("70000000-0000-0000-0000-000000000101");
internal static readonly Guid TemplateBgwDomainContosoId = Guid.Parse("70000000-0000-0000-0000-000000000102");
internal static readonly Guid TemplateBgwSharePointContosoId = Guid.Parse("70000000-0000-0000-0000-000000000103");
internal static readonly Guid TemplateBgwStageInstallId = Guid.Parse("70000000-0000-0000-0000-000000000104");
internal static readonly Guid TemplateActiveDirectoryVersionId = Guid.Parse("71000000-0000-0000-0000-000000000001");
internal static readonly Guid TemplateSqlServerVersionId = Guid.Parse("71000000-0000-0000-0000-000000000002");
internal static readonly Guid TemplateSharePointVersionId = Guid.Parse("71000000-0000-0000-0000-000000000003");
internal static readonly Guid TemplateTeamsVersionId = Guid.Parse("71000000-0000-0000-0000-000000000004");
internal static readonly Guid TemplateBgwEnvironmentTestVersionId = Guid.Parse("71000000-0000-0000-0000-000000000101");
internal static readonly Guid TemplateBgwDomainContosoVersionId = Guid.Parse("71000000-0000-0000-0000-000000000102");
internal static readonly Guid TemplateBgwSharePointContosoVersionId = Guid.Parse("71000000-0000-0000-0000-000000000103");
internal static readonly Guid TemplateBgwStageInstallVersionId = Guid.Parse("71000000-0000-0000-0000-000000000104");
internal static readonly Guid DeploymentBatchSharePointId = Guid.Parse("80000000-0000-0000-0000-000000000001");
internal static readonly Guid DeploymentBatchBgwMergeId = Guid.Parse("80000000-0000-0000-0000-000000000101");
internal static readonly Guid DeploymentSp01Id = Guid.Parse("81000000-0000-0000-0000-000000000001");
internal static readonly Guid DeploymentSp02Id = Guid.Parse("81000000-0000-0000-0000-000000000002");
internal static readonly Guid DeploymentBgwSp01Id = Guid.Parse("81000000-0000-0000-0000-000000000101");
internal static readonly Guid DeploymentBgwSp02Id = Guid.Parse("81000000-0000-0000-0000-000000000102");
internal static readonly Guid DeploymentBgwSp03Id = Guid.Parse("81000000-0000-0000-0000-000000000103");
internal static readonly Guid DeploymentSharePointTemplateSelectionId = Guid.Parse("82000000-0000-0000-0000-000000000001");
internal static readonly Guid DeploymentBgwEnvironmentSelectionId = Guid.Parse("82000000-0000-0000-0000-000000000101");
internal static readonly Guid DeploymentBgwDomainSelectionId = Guid.Parse("82000000-0000-0000-0000-000000000102");
internal static readonly Guid DeploymentBgwSharePointSelectionId = Guid.Parse("82000000-0000-0000-0000-000000000103");
internal static readonly Guid DeploymentBgwStageSelectionId = Guid.Parse("82000000-0000-0000-0000-000000000104");
internal static readonly Guid DeploymentParameterDatabasePrefixId = Guid.Parse("83000000-0000-0000-0000-000000000001");
internal static readonly Guid DeploymentParameterFarmAccountId = Guid.Parse("83000000-0000-0000-0000-000000000002");
internal static readonly Guid DeploymentTargetSp01Id = Guid.Parse("84000000-0000-0000-0000-000000000001");
internal static readonly Guid DeploymentTargetSp02Id = Guid.Parse("84000000-0000-0000-0000-000000000002");
internal static readonly Guid DeploymentTargetBgwSp01Id = Guid.Parse("84000000-0000-0000-0000-000000000101");
internal static readonly Guid DeploymentTargetBgwSp02Id = Guid.Parse("84000000-0000-0000-0000-000000000102");
internal static readonly Guid DeploymentTargetBgwSp03Id = Guid.Parse("84000000-0000-0000-0000-000000000103");
internal static void Seed(ModelBuilder modelBuilder)
{
@@ -105,7 +129,10 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
Base(new TargetModel { Id = VmSp01Id, DomainID = DomainCentralId, Name = "CT-SHP-01", TargetType = "VirtualMachine", ProviderType = "OnPrem", MetadataJson = "{\"role\":\"SharePoint\",\"environment\":\"Test\"}" }),
Base(new TargetModel { Id = VmSp02Id, DomainID = DomainCentralId, Name = "CT-SHP-02", TargetType = "VirtualMachine", ProviderType = "OnPrem", MetadataJson = "{\"role\":\"SharePoint\",\"environment\":\"Test\"}" }),
Base(new TargetModel { Id = TargetM365TenantId, Name = "contoso.onmicrosoft.com", TargetType = "Tenant", ProviderType = "Microsoft365", ExternalId = "11111111-1111-1111-1111-111111111111", MetadataJson = "{\"environment\":\"Production\",\"workload\":\"M365\"}" }),
Base(new TargetModel { Id = TargetTeamsPolicyScopeId, Name = "Teams - Standard Users", TargetType = "PolicyScope", ProviderType = "Microsoft365", ExternalId = "Teams.StandardUsers", MetadataJson = "{\"workload\":\"Teams\",\"scope\":\"StandardUsers\"}" })
Base(new TargetModel { Id = TargetTeamsPolicyScopeId, Name = "Teams - Standard Users", TargetType = "PolicyScope", ProviderType = "Microsoft365", ExternalId = "Teams.StandardUsers", MetadataJson = "{\"workload\":\"Teams\",\"scope\":\"StandardUsers\"}" }),
Base(new TargetModel { Id = TargetBgwSp01Id, DomainID = DomainCentralId, Name = "CLD-SHP-01", TargetType = "VirtualMachine", ProviderType = "OnPrem", MetadataJson = "{\"role\":\"SharePoint\",\"environment\":\"Test\",\"source\":\"Test.Merge.ps1\"}" }),
Base(new TargetModel { Id = TargetBgwSp02Id, DomainID = DomainCentralId, Name = "CLD-SHP-02", TargetType = "VirtualMachine", ProviderType = "OnPrem", MetadataJson = "{\"role\":\"SharePoint\",\"environment\":\"Test\",\"source\":\"Test.Merge.ps1\"}" }),
Base(new TargetModel { Id = TargetBgwSp03Id, DomainID = DomainCentralId, Name = "CLD-SHP-03", TargetType = "VirtualMachine", ProviderType = "OnPrem", MetadataJson = "{\"role\":\"SharePoint\",\"environment\":\"Test\",\"source\":\"Test.Merge.ps1\"}" })
];
private static object[] Services() =>
@@ -113,7 +140,8 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
Base(new ServiceModel { Id = ServiceActiveDirectoryId, Name = "Active Directory", Description = "On-premises directory and identity service.", IconKey = "network", IsCloudService = false }),
Base(new ServiceModel { Id = ServiceSqlServerId, Name = "SQL Server", Description = "Database platform for application workloads.", IconKey = "database", IsCloudService = false }),
Base(new ServiceModel { Id = ServiceSharePointId, Name = "SharePoint Server", Description = "Collaboration platform for on-premises workloads.", IconKey = "sharepoint", IsCloudService = false }),
Base(new ServiceModel { Id = ServiceTeamsId, Name = "Microsoft Teams", Description = "Cloud collaboration workload in Microsoft 365.", IconKey = "messages-square", IsCloudService = true })
Base(new ServiceModel { Id = ServiceTeamsId, Name = "Microsoft Teams", Description = "Cloud collaboration workload in Microsoft 365.", IconKey = "messages-square", IsCloudService = true }),
Base(new ServiceModel { Id = ServiceConfigurationDataId, Name = "DSC Configuration Data", Description = "Reusable configuration-data template building blocks for deployment composition.", IconKey = "braces", IsCloudService = false })
];
private static object[] ServiceRoleDefinitions() =>
@@ -129,7 +157,8 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
Base(new TemplateCategoryModel { Id = CategoryActiveDirectoryId, ServiceId = ServiceActiveDirectoryId, Name = "Domain Services", Description = "Templates for domain controller and domain configuration.", Color = "#2563EB", IsActive = true }),
Base(new TemplateCategoryModel { Id = CategorySqlServerId, ServiceId = ServiceSqlServerId, Name = "Database Platform", Description = "Templates for SQL Server workloads.", Color = "#16A34A", IsActive = true }),
Base(new TemplateCategoryModel { Id = CategorySharePointId, ServiceId = ServiceSharePointId, Name = "Collaboration Farm", Description = "Templates for SharePoint Server farms.", Color = "#0F766E", IsActive = true }),
Base(new TemplateCategoryModel { Id = CategoryTeamsId, ServiceId = ServiceTeamsId, Name = "Teams Policies", Description = "Templates for Teams policy configuration.", Color = "#7C3AED", IsActive = true })
Base(new TemplateCategoryModel { Id = CategoryTeamsId, ServiceId = ServiceTeamsId, Name = "Teams Policies", Description = "Templates for Teams policy configuration.", Color = "#7C3AED", IsActive = true }),
Base(new TemplateCategoryModel { Id = CategoryBgwMergeTemplatesId, ServiceId = ServiceConfigurationDataId, Name = "Test.Merge.ps1 Templates", Description = "Materialized template building blocks from the BGW Test.Merge.ps1 scenario.", Color = "#2563EB", IsActive = true })
];
private static object[] DeploymentRules() =>
@@ -149,7 +178,11 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
Base(new TemplateModel { Id = TemplateActiveDirectoryId, TemplateCategoryId = CategoryActiveDirectoryId, DeploymentRuleId = RuleStandardId, Name = "Contoso Active Directory Domain", Version = "1.0.0", Description = "Creates a reusable Active Directory domain baseline.", JSONData = ActiveDirectoryTemplateJson }),
Base(new TemplateModel { Id = TemplateSqlServerId, TemplateCategoryId = CategorySqlServerId, DeploymentRuleId = RuleStandardId, Name = "Contoso SQL Server", Version = "1.0.0", Description = "Creates a SQL Server baseline for application workloads.", JSONData = SqlServerTemplateJson }),
Base(new TemplateModel { Id = TemplateSharePointId, TemplateCategoryId = CategorySharePointId, DeploymentRuleId = RuleStandardId, Name = "Contoso SharePoint Server", Version = "1.0.0", Description = "Creates a SharePoint Server farm baseline.", JSONData = SharePointTemplateJson }),
Base(new TemplateModel { Id = TemplateTeamsId, TemplateCategoryId = CategoryTeamsId, DeploymentRuleId = RuleStandardId, Name = "Contoso Teams Policies", Version = "1.0.0", Description = "Creates a Microsoft Teams policy baseline.", JSONData = TeamsTemplateJson })
Base(new TemplateModel { Id = TemplateTeamsId, TemplateCategoryId = CategoryTeamsId, DeploymentRuleId = RuleStandardId, Name = "Contoso Teams Policies", Version = "1.0.0", Description = "Creates a Microsoft Teams policy baseline.", JSONData = TeamsTemplateJson }),
Base(new TemplateModel { Id = TemplateBgwEnvironmentTestId, TemplateCategoryId = CategoryBgwMergeTemplatesId, DeploymentRuleId = RuleStandardId, Name = "BGW Environment Test", Version = "1.0.0", Description = "Materialized Environment/Test.psd1 template from Test.Merge.ps1.", JSONData = BgwEnvironmentTestTemplateJson }),
Base(new TemplateModel { Id = TemplateBgwDomainContosoId, TemplateCategoryId = CategoryBgwMergeTemplatesId, DeploymentRuleId = RuleStandardId, Name = "BGW Domain Contoso", Version = "1.0.0", Description = "Materialized Domain/Contoso.psd1 template from Test.Merge.ps1.", JSONData = BgwDomainContosoTemplateJson }),
Base(new TemplateModel { Id = TemplateBgwSharePointContosoId, TemplateCategoryId = CategoryBgwMergeTemplatesId, DeploymentRuleId = RuleStandardId, Name = "BGW SharePoint Contoso", Version = "1.0.0", Description = "Materialized Service/SharePoint/Contoso.psd1 template from Test.Merge.ps1.", JSONData = BgwSharePointContosoTemplateJson }),
Base(new TemplateModel { Id = TemplateBgwStageInstallId, TemplateCategoryId = CategoryBgwMergeTemplatesId, DeploymentRuleId = RuleStandardId, Name = "BGW Stage Install", Version = "1.0.0", Description = "Materialized Stage/Install.psd1 template from Test.Merge.ps1.", JSONData = BgwStageInstallTemplateJson })
];
private static object[] TemplateVersions() =>
@@ -157,23 +190,35 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
TemplateVersion(TemplateActiveDirectoryVersionId, TemplateActiveDirectoryId, ActiveDirectoryTemplateJson),
TemplateVersion(TemplateSqlServerVersionId, TemplateSqlServerId, SqlServerTemplateJson),
TemplateVersion(TemplateSharePointVersionId, TemplateSharePointId, SharePointTemplateJson),
TemplateVersion(TemplateTeamsVersionId, TemplateTeamsId, TeamsTemplateJson)
TemplateVersion(TemplateTeamsVersionId, TemplateTeamsId, TeamsTemplateJson),
TemplateVersion(TemplateBgwEnvironmentTestVersionId, TemplateBgwEnvironmentTestId, BgwEnvironmentTestTemplateJson),
TemplateVersion(TemplateBgwDomainContosoVersionId, TemplateBgwDomainContosoId, BgwDomainContosoTemplateJson),
TemplateVersion(TemplateBgwSharePointContosoVersionId, TemplateBgwSharePointContosoId, BgwSharePointContosoTemplateJson),
TemplateVersion(TemplateBgwStageInstallVersionId, TemplateBgwStageInstallId, BgwStageInstallTemplateJson)
];
private static object[] DeploymentBatches() =>
[
Base(new DeploymentGroupModel { Id = DeploymentBatchSharePointId, TemplateId = TemplateSharePointId, DeploymentRuleId = RuleStandardId, Status = QueueJobStatus.Pending })
Base(new DeploymentGroupModel { Id = DeploymentBatchSharePointId, TemplateId = TemplateSharePointId, DeploymentRuleId = RuleStandardId, Status = QueueJobStatus.Pending }),
Base(new DeploymentGroupModel { Id = DeploymentBatchBgwMergeId, TemplateId = TemplateBgwSharePointContosoId, DeploymentRuleId = RuleStandardId, Status = QueueJobStatus.Pending })
];
private static object[] Deployments() =>
[
Base(new DeploymentModel { Id = DeploymentSp01Id, DeploymentGroupId = DeploymentBatchSharePointId, TargetId = VmSp01Id, Status = QueueJobStatus.Pending, JSONData = "{\"role\":\"WebFrontEnd\"}" }),
Base(new DeploymentModel { Id = DeploymentSp02Id, DeploymentGroupId = DeploymentBatchSharePointId, TargetId = VmSp02Id, Status = QueueJobStatus.Pending, JSONData = "{\"role\":\"Application\"}" })
Base(new DeploymentModel { Id = DeploymentSp02Id, DeploymentGroupId = DeploymentBatchSharePointId, TargetId = VmSp02Id, Status = QueueJobStatus.Pending, JSONData = "{\"role\":\"Application\"}" }),
Base(new DeploymentModel { Id = DeploymentBgwSp01Id, DeploymentGroupId = DeploymentBatchBgwMergeId, TargetId = TargetBgwSp01Id, Status = QueueJobStatus.Pending, JSONData = "{\"role\":\"Node\"}" }),
Base(new DeploymentModel { Id = DeploymentBgwSp02Id, DeploymentGroupId = DeploymentBatchBgwMergeId, TargetId = TargetBgwSp02Id, Status = QueueJobStatus.Pending, JSONData = "{\"role\":\"Node\"}" }),
Base(new DeploymentModel { Id = DeploymentBgwSp03Id, DeploymentGroupId = DeploymentBatchBgwMergeId, TargetId = TargetBgwSp03Id, Status = QueueJobStatus.Pending, JSONData = "{\"role\":\"Node\"}" })
];
private static object[] DeploymentTemplateSelections() =>
[
Base(new DeploymentTemplateSelectionModel { Id = DeploymentSharePointTemplateSelectionId, DeploymentGroupId = DeploymentBatchSharePointId, TemplateVersionId = TemplateSharePointVersionId, TemplateRole = "Service", SortOrder = 10, Alias = "SharePoint" })
Base(new DeploymentTemplateSelectionModel { Id = DeploymentSharePointTemplateSelectionId, DeploymentGroupId = DeploymentBatchSharePointId, TemplateVersionId = TemplateSharePointVersionId, TemplateRole = "Service", SortOrder = 10, Alias = "SharePoint" }),
Base(new DeploymentTemplateSelectionModel { Id = DeploymentBgwEnvironmentSelectionId, DeploymentGroupId = DeploymentBatchBgwMergeId, TemplateVersionId = TemplateBgwEnvironmentTestVersionId, TemplateRole = "Environment", SortOrder = 10, Alias = "Environment-Test" }),
Base(new DeploymentTemplateSelectionModel { Id = DeploymentBgwDomainSelectionId, DeploymentGroupId = DeploymentBatchBgwMergeId, TemplateVersionId = TemplateBgwDomainContosoVersionId, TemplateRole = "Domain", SortOrder = 20, Alias = "Domain-Contoso" }),
Base(new DeploymentTemplateSelectionModel { Id = DeploymentBgwSharePointSelectionId, DeploymentGroupId = DeploymentBatchBgwMergeId, TemplateVersionId = TemplateBgwSharePointContosoVersionId, TemplateRole = "Service", SortOrder = 30, Alias = "Service-SharePoint-Contoso" }),
Base(new DeploymentTemplateSelectionModel { Id = DeploymentBgwStageSelectionId, DeploymentGroupId = DeploymentBatchBgwMergeId, TemplateVersionId = TemplateBgwStageInstallVersionId, TemplateRole = "Stage", SortOrder = 40, Alias = "Stage-Install" })
];
private static object[] DeploymentParameterValues() =>
@@ -185,7 +230,10 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
private static object[] DeploymentTargetAssignments() =>
[
Base(new DeploymentTargetAssignmentModel { Id = DeploymentTargetSp01Id, DeploymentGroupId = DeploymentBatchSharePointId, TargetId = VmSp01Id, RoleKey = "WebFrontEnd", SortOrder = 10, NodeDataJson = "{\"nodeName\":\"CT-SHP-01\"}" }),
Base(new DeploymentTargetAssignmentModel { Id = DeploymentTargetSp02Id, DeploymentGroupId = DeploymentBatchSharePointId, TargetId = VmSp02Id, RoleKey = "Application", SortOrder = 20, NodeDataJson = "{\"nodeName\":\"CT-SHP-02\"}" })
Base(new DeploymentTargetAssignmentModel { Id = DeploymentTargetSp02Id, DeploymentGroupId = DeploymentBatchSharePointId, TargetId = VmSp02Id, RoleKey = "Application", SortOrder = 20, NodeDataJson = "{\"nodeName\":\"CT-SHP-02\"}" }),
Base(new DeploymentTargetAssignmentModel { Id = DeploymentTargetBgwSp01Id, DeploymentGroupId = DeploymentBatchBgwMergeId, TargetId = TargetBgwSp01Id, RoleKey = "Node", SortOrder = 10, NodeDataJson = "{\"nodeName\":\"CLD-SHP-01\",\"RunCentralAdministration\":true}" }),
Base(new DeploymentTargetAssignmentModel { Id = DeploymentTargetBgwSp02Id, DeploymentGroupId = DeploymentBatchBgwMergeId, TargetId = TargetBgwSp02Id, RoleKey = "Node", SortOrder = 20, NodeDataJson = "{\"nodeName\":\"CLD-SHP-02\",\"RunCentralAdministration\":false}" }),
Base(new DeploymentTargetAssignmentModel { Id = DeploymentTargetBgwSp03Id, DeploymentGroupId = DeploymentBatchBgwMergeId, TargetId = TargetBgwSp03Id, RoleKey = "Node", SortOrder = 30, NodeDataJson = "{\"nodeName\":\"CLD-SHP-03\",\"RunCentralAdministration\":false}" })
];
private static TemplateVersionModel TemplateVersion(Guid id, Guid templateId, string jsonData)