using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace ClassNotify.Server.Data.Migrations { /// public partial class AddDeviceSelfCheckBatch : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "BatchId", table: "DeviceSelfChecks", type: "character varying(100)", maxLength: 100, nullable: true); migrationBuilder.AddColumn( name: "DeadlineAtUtc", table: "DeviceSelfChecks", type: "timestamp with time zone", nullable: false, defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0))); migrationBuilder.AddColumn( name: "DispatchAttemptCount", table: "DeviceSelfChecks", type: "integer", nullable: false, defaultValue: 0); migrationBuilder.AddColumn( name: "DispatchedAtUtc", table: "DeviceSelfChecks", type: "timestamp with time zone", nullable: true); migrationBuilder.AddColumn( name: "OverallStatus", table: "DeviceSelfChecks", type: "character varying(32)", maxLength: 32, nullable: true); migrationBuilder.AddColumn( name: "RunState", table: "DeviceSelfChecks", type: "character varying(32)", maxLength: 32, nullable: false, defaultValue: "PendingDispatch"); migrationBuilder.CreateTable( name: "DeviceSelfCheckBatches", columns: table => new { Id = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), CorrelationId = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), ClientRequestId = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), CreatedByUserId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), DeadlineAtUtc = table.Column(type: "timestamp with time zone", nullable: false), CompletedAtUtc = table.Column(type: "timestamp with time zone", nullable: true), TargetDeviceCount = table.Column(type: "integer", nullable: false), Status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DeviceSelfCheckBatches", x => x.Id); }); migrationBuilder.CreateIndex( name: "IX_DeviceSelfChecks_BatchId_DeviceId", table: "DeviceSelfChecks", columns: new[] { "BatchId", "DeviceId" }, unique: true, filter: "\"BatchId\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_DeviceSelfChecks_BatchId_OverallStatus", table: "DeviceSelfChecks", columns: new[] { "BatchId", "OverallStatus" }); migrationBuilder.CreateIndex( name: "IX_DeviceSelfChecks_BatchId_RunState", table: "DeviceSelfChecks", columns: new[] { "BatchId", "RunState" }); migrationBuilder.CreateIndex( name: "IX_DeviceSelfCheckBatches_CreatedAtUtc", table: "DeviceSelfCheckBatches", column: "CreatedAtUtc"); migrationBuilder.CreateIndex( name: "IX_DeviceSelfCheckBatches_CreatedByUserId_ClientRequestId", table: "DeviceSelfCheckBatches", columns: new[] { "CreatedByUserId", "ClientRequestId" }, unique: true); migrationBuilder.AddForeignKey( name: "FK_DeviceSelfChecks_DeviceSelfCheckBatches_BatchId", table: "DeviceSelfChecks", column: "BatchId", principalTable: "DeviceSelfCheckBatches", principalColumn: "Id", onDelete: ReferentialAction.Restrict); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_DeviceSelfChecks_DeviceSelfCheckBatches_BatchId", table: "DeviceSelfChecks"); migrationBuilder.DropTable( name: "DeviceSelfCheckBatches"); migrationBuilder.DropIndex( name: "IX_DeviceSelfChecks_BatchId_DeviceId", table: "DeviceSelfChecks"); migrationBuilder.DropIndex( name: "IX_DeviceSelfChecks_BatchId_OverallStatus", table: "DeviceSelfChecks"); migrationBuilder.DropIndex( name: "IX_DeviceSelfChecks_BatchId_RunState", table: "DeviceSelfChecks"); migrationBuilder.DropColumn( name: "BatchId", table: "DeviceSelfChecks"); migrationBuilder.DropColumn( name: "DeadlineAtUtc", table: "DeviceSelfChecks"); migrationBuilder.DropColumn( name: "DispatchAttemptCount", table: "DeviceSelfChecks"); migrationBuilder.DropColumn( name: "DispatchedAtUtc", table: "DeviceSelfChecks"); migrationBuilder.DropColumn( name: "OverallStatus", table: "DeviceSelfChecks"); migrationBuilder.DropColumn( name: "RunState", table: "DeviceSelfChecks"); } } }