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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,294 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Microsoft.SelfService.Portal.Core.API.Migrations
{
/// <inheritdoc />
public partial class AddQueueHardening : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_DeploymentJobTargets_DeploymentJobId",
table: "DeploymentJobTargets");
migrationBuilder.DropIndex(
name: "IX_DeploymentJobSteps_DeploymentJobId",
table: "DeploymentJobSteps");
migrationBuilder.AlterColumn<string>(
name: "Status",
table: "DeploymentJobTargets",
type: "nvarchar(450)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
migrationBuilder.AddColumn<DateTime>(
name: "Finished",
table: "DeploymentJobTargets",
type: "datetime2",
nullable: true)
.Annotation("Relational:ColumnOrder", 9);
migrationBuilder.AddColumn<string>(
name: "OutputMetadataJson",
table: "DeploymentJobTargets",
type: "nvarchar(max)",
nullable: true)
.Annotation("Relational:ColumnOrder", 10);
migrationBuilder.AddColumn<DateTime>(
name: "Started",
table: "DeploymentJobTargets",
type: "datetime2",
nullable: true)
.Annotation("Relational:ColumnOrder", 8);
migrationBuilder.AlterColumn<string>(
name: "Status",
table: "DeploymentJobSteps",
type: "nvarchar(450)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
migrationBuilder.AddColumn<string>(
name: "ErrorMessage",
table: "DeploymentJobSteps",
type: "nvarchar(max)",
nullable: true)
.Annotation("Relational:ColumnOrder", 14);
migrationBuilder.AddColumn<DateTime>(
name: "Finished",
table: "DeploymentJobSteps",
type: "datetime2",
nullable: true)
.Annotation("Relational:ColumnOrder", 12);
migrationBuilder.AddColumn<string>(
name: "OutputMetadataJson",
table: "DeploymentJobSteps",
type: "nvarchar(max)",
nullable: true)
.Annotation("Relational:ColumnOrder", 13);
migrationBuilder.AddColumn<DateTime>(
name: "Started",
table: "DeploymentJobSteps",
type: "datetime2",
nullable: true)
.Annotation("Relational:ColumnOrder", 11);
migrationBuilder.AlterColumn<string>(
name: "Status",
table: "DeploymentJobs",
type: "nvarchar(450)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
migrationBuilder.AddColumn<Guid>(
name: "CorrelationId",
table: "DeploymentJobs",
type: "uniqueidentifier",
nullable: false,
defaultValueSql: "NEWID()")
.Annotation("Relational:ColumnOrder", 13);
migrationBuilder.AddColumn<DateTime>(
name: "HeartbeatAt",
table: "DeploymentJobs",
type: "datetime2",
nullable: true)
.Annotation("Relational:ColumnOrder", 16);
migrationBuilder.AddColumn<int>(
name: "Priority",
table: "DeploymentJobs",
type: "int",
nullable: false,
defaultValue: 100)
.Annotation("Relational:ColumnOrder", 14);
migrationBuilder.AddColumn<byte[]>(
name: "RowVersion",
table: "DeploymentJobs",
type: "rowversion",
rowVersion: true,
nullable: false,
defaultValue: new byte[0]);
migrationBuilder.AddColumn<DateTime>(
name: "ScheduledAt",
table: "DeploymentJobs",
type: "datetime2",
nullable: true)
.Annotation("Relational:ColumnOrder", 15);
migrationBuilder.AddColumn<string>(
name: "WorkerName",
table: "DeploymentJobs",
type: "nvarchar(450)",
nullable: true)
.Annotation("Relational:ColumnOrder", 17);
migrationBuilder.CreateIndex(
name: "IX_DeploymentJobTargets_DeploymentJobId_Status",
table: "DeploymentJobTargets",
columns: new[] { "DeploymentJobId", "Status" });
migrationBuilder.AddCheckConstraint(
name: "CK_DeploymentJobTargets_OutputMetadataJson_IsJson",
table: "DeploymentJobTargets",
sql: "[OutputMetadataJson] IS NULL OR ISJSON([OutputMetadataJson]) = 1");
migrationBuilder.CreateIndex(
name: "IX_DeploymentJobSteps_DeploymentJobId_Status_SortOrder",
table: "DeploymentJobSteps",
columns: new[] { "DeploymentJobId", "Status", "SortOrder" });
migrationBuilder.AddCheckConstraint(
name: "CK_DeploymentJobSteps_OutputMetadataJson_IsJson",
table: "DeploymentJobSteps",
sql: "[OutputMetadataJson] IS NULL OR ISJSON([OutputMetadataJson]) = 1");
migrationBuilder.CreateIndex(
name: "IX_DeploymentJobs_CorrelationId",
table: "DeploymentJobs",
column: "CorrelationId");
migrationBuilder.CreateIndex(
name: "IX_DeploymentJobs_Status_ScheduledAt_LockedUntil_Priority_Created",
table: "DeploymentJobs",
columns: new[] { "Status", "ScheduledAt", "LockedUntil", "Priority", "Created" });
migrationBuilder.CreateIndex(
name: "IX_DeploymentJobs_WorkerName",
table: "DeploymentJobs",
column: "WorkerName");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_DeploymentJobTargets_DeploymentJobId_Status",
table: "DeploymentJobTargets");
migrationBuilder.DropCheckConstraint(
name: "CK_DeploymentJobTargets_OutputMetadataJson_IsJson",
table: "DeploymentJobTargets");
migrationBuilder.DropIndex(
name: "IX_DeploymentJobSteps_DeploymentJobId_Status_SortOrder",
table: "DeploymentJobSteps");
migrationBuilder.DropCheckConstraint(
name: "CK_DeploymentJobSteps_OutputMetadataJson_IsJson",
table: "DeploymentJobSteps");
migrationBuilder.DropIndex(
name: "IX_DeploymentJobs_CorrelationId",
table: "DeploymentJobs");
migrationBuilder.DropIndex(
name: "IX_DeploymentJobs_Status_ScheduledAt_LockedUntil_Priority_Created",
table: "DeploymentJobs");
migrationBuilder.DropIndex(
name: "IX_DeploymentJobs_WorkerName",
table: "DeploymentJobs");
migrationBuilder.DropColumn(
name: "Finished",
table: "DeploymentJobTargets");
migrationBuilder.DropColumn(
name: "OutputMetadataJson",
table: "DeploymentJobTargets");
migrationBuilder.DropColumn(
name: "Started",
table: "DeploymentJobTargets");
migrationBuilder.DropColumn(
name: "ErrorMessage",
table: "DeploymentJobSteps");
migrationBuilder.DropColumn(
name: "Finished",
table: "DeploymentJobSteps");
migrationBuilder.DropColumn(
name: "OutputMetadataJson",
table: "DeploymentJobSteps");
migrationBuilder.DropColumn(
name: "Started",
table: "DeploymentJobSteps");
migrationBuilder.DropColumn(
name: "CorrelationId",
table: "DeploymentJobs");
migrationBuilder.DropColumn(
name: "HeartbeatAt",
table: "DeploymentJobs");
migrationBuilder.DropColumn(
name: "Priority",
table: "DeploymentJobs");
migrationBuilder.DropColumn(
name: "RowVersion",
table: "DeploymentJobs");
migrationBuilder.DropColumn(
name: "ScheduledAt",
table: "DeploymentJobs");
migrationBuilder.DropColumn(
name: "WorkerName",
table: "DeploymentJobs");
migrationBuilder.AlterColumn<string>(
name: "Status",
table: "DeploymentJobTargets",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(450)");
migrationBuilder.AlterColumn<string>(
name: "Status",
table: "DeploymentJobSteps",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(450)");
migrationBuilder.AlterColumn<string>(
name: "Status",
table: "DeploymentJobs",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(450)");
migrationBuilder.CreateIndex(
name: "IX_DeploymentJobTargets_DeploymentJobId",
table: "DeploymentJobTargets",
column: "DeploymentJobId");
migrationBuilder.CreateIndex(
name: "IX_DeploymentJobSteps_DeploymentJobId",
table: "DeploymentJobSteps",
column: "DeploymentJobId");
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long