using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Microsoft.SelfService.Portal.Core.API.Migrations { /// public partial class AddDeploymentRulesAndQueueJobSteps : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "DeploymentRuleId", table: "Templates", type: "uniqueidentifier", nullable: true) .Annotation("Relational:ColumnOrder", 6); migrationBuilder.AddColumn( name: "MetadataJson", table: "QueueJobs", type: "nvarchar(max)", nullable: true) .Annotation("Relational:ColumnOrder", 11); migrationBuilder.AddColumn( name: "RuleSnapshotJson", table: "QueueJobs", type: "nvarchar(max)", nullable: true) .Annotation("Relational:ColumnOrder", 12); migrationBuilder.CreateTable( name: "DeploymentRules", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), Name = table.Column(type: "nvarchar(max)", nullable: false), Description = table.Column(type: "nvarchar(max)", nullable: true), IsActive = table.Column(type: "bit", nullable: false), Modified = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()"), ModifiedBy = table.Column(type: "nvarchar(max)", nullable: false), Created = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()"), CreatedBy = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DeploymentRules", x => x.Id); }); migrationBuilder.CreateTable( name: "QueueJobSteps", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), QueueJobId = table.Column(type: "uniqueidentifier", nullable: false), DependsOnQueueJobStepId = table.Column(type: "uniqueidentifier", nullable: true), SortOrder = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), StepType = table.Column(type: "nvarchar(max)", nullable: false), Status = table.Column(type: "nvarchar(max)", nullable: false), MetadataJson = table.Column(type: "nvarchar(max)", nullable: true), ApprovedAt = table.Column(type: "datetime2", nullable: true), ApprovedBy = table.Column(type: "nvarchar(max)", nullable: true), ApprovalComment = table.Column(type: "nvarchar(max)", nullable: true), Modified = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()"), ModifiedBy = table.Column(type: "nvarchar(max)", nullable: false), Created = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()"), CreatedBy = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_QueueJobSteps", x => x.Id); table.ForeignKey( name: "FK_QueueJobSteps_QueueJobSteps_DependsOnQueueJobStepId", column: x => x.DependsOnQueueJobStepId, principalTable: "QueueJobSteps", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_QueueJobSteps_QueueJobs_QueueJobId", column: x => x.QueueJobId, principalTable: "QueueJobs", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "DeploymentRuleSteps", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), DeploymentRuleId = table.Column(type: "uniqueidentifier", nullable: false), SortOrder = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), StepType = table.Column(type: "nvarchar(max)", nullable: false), RequiresApproval = table.Column(type: "bit", nullable: false), MetadataJson = table.Column(type: "nvarchar(max)", nullable: true), Modified = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()"), ModifiedBy = table.Column(type: "nvarchar(max)", nullable: false), Created = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETDATE()"), CreatedBy = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DeploymentRuleSteps", x => x.Id); table.ForeignKey( name: "FK_DeploymentRuleSteps_DeploymentRules_DeploymentRuleId", column: x => x.DeploymentRuleId, principalTable: "DeploymentRules", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Templates_DeploymentRuleId", table: "Templates", column: "DeploymentRuleId"); migrationBuilder.CreateIndex( name: "IX_DeploymentRuleSteps_DeploymentRuleId", table: "DeploymentRuleSteps", column: "DeploymentRuleId"); migrationBuilder.CreateIndex( name: "IX_QueueJobSteps_DependsOnQueueJobStepId", table: "QueueJobSteps", column: "DependsOnQueueJobStepId"); migrationBuilder.CreateIndex( name: "IX_QueueJobSteps_QueueJobId", table: "QueueJobSteps", column: "QueueJobId"); migrationBuilder.AddForeignKey( name: "FK_Templates_DeploymentRules_DeploymentRuleId", table: "Templates", column: "DeploymentRuleId", principalTable: "DeploymentRules", principalColumn: "Id"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Templates_DeploymentRules_DeploymentRuleId", table: "Templates"); migrationBuilder.DropTable( name: "DeploymentRuleSteps"); migrationBuilder.DropTable( name: "QueueJobSteps"); migrationBuilder.DropTable( name: "DeploymentRules"); migrationBuilder.DropIndex( name: "IX_Templates_DeploymentRuleId", table: "Templates"); migrationBuilder.DropColumn( name: "DeploymentRuleId", table: "Templates"); migrationBuilder.DropColumn( name: "MetadataJson", table: "QueueJobs"); migrationBuilder.DropColumn( name: "RuleSnapshotJson", table: "QueueJobs"); } } }