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

@@ -93,6 +93,21 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
modelBuilder.Entity<QueueJobModel>()
.ToTable("DeploymentJobs");
modelBuilder.Entity<QueueJobModel>()
.HasIndex(job => new { job.Status, job.ScheduledAt, job.LockedUntil, job.Priority, job.Created });
modelBuilder.Entity<QueueJobModel>()
.HasIndex(job => job.CorrelationId);
modelBuilder.Entity<QueueJobModel>()
.HasIndex(job => job.WorkerName);
modelBuilder.Entity<QueueJobModel>()
.Property(job => job.CorrelationId)
.HasDefaultValueSql("NEWID()");
modelBuilder.Entity<QueueJobModel>()
.Property(job => job.Priority)
.HasDefaultValue(100);
modelBuilder.Entity<QueueJobModel>()
.Property(job => job.RowVersion)
.IsRowVersion();
modelBuilder.Entity<QueueJobTargetModel>()
.ToTable("DeploymentJobTargets");
@@ -102,6 +117,10 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
modelBuilder.Entity<QueueJobTargetModel>()
.Property(target => target.DeploymentGroupId)
.HasColumnName("DeploymentBatchId");
modelBuilder.Entity<QueueJobTargetModel>()
.HasIndex(target => new { target.QueueJobId, target.Status });
modelBuilder.Entity<QueueJobTargetModel>()
.ToTable(table => table.HasCheckConstraint("CK_DeploymentJobTargets_OutputMetadataJson_IsJson", "[OutputMetadataJson] IS NULL OR ISJSON([OutputMetadataJson]) = 1"));
modelBuilder.Entity<QueueJobStepModel>()
.ToTable("DeploymentJobSteps");
@@ -111,6 +130,10 @@ namespace Microsoft.SelfService.Portal.Core.API.Context
modelBuilder.Entity<QueueJobStepModel>()
.Property(step => step.DependsOnQueueJobStepId)
.HasColumnName("DependsOnDeploymentJobStepId");
modelBuilder.Entity<QueueJobStepModel>()
.HasIndex(step => new { step.QueueJobId, step.Status, step.SortOrder });
modelBuilder.Entity<QueueJobStepModel>()
.ToTable(table => table.HasCheckConstraint("CK_DeploymentJobSteps_OutputMetadataJson_IsJson", "[OutputMetadataJson] IS NULL OR ISJSON([OutputMetadataJson]) = 1"));
modelBuilder.Entity<DeploymentModel>()
.HasKey(d => new { d.TargetId, d.DeploymentGroupId });