using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ClassNotify.Server.Data.Migrations
{
///
public partial class AddDeviceSupportBundle : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "DeviceSupportBundles",
columns: table => new
{
Id = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
ClientRequestId = table.Column(type: "character varying(64)", maxLength: 64, nullable: false),
TenantId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
DeviceId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
CorrelationId = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
RequestedByUserId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
Status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false),
UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false),
DeadlineAtUtc = table.Column(type: "timestamp with time zone", nullable: false),
DispatchedAtUtc = table.Column(type: "timestamp with time zone", nullable: true),
CompletedAtUtc = table.Column(type: "timestamp with time zone", nullable: true),
ExpiresAtUtc = table.Column(type: "timestamp with time zone", nullable: true),
DispatchAttemptCount = table.Column(type: "integer", nullable: false),
LastDispatchAttemptAtUtc = table.Column(type: "timestamp with time zone", nullable: true),
NextDispatchAttemptAtUtc = table.Column(type: "timestamp with time zone", nullable: true),
StoragePath = table.Column(type: "character varying(500)", maxLength: 500, nullable: true),
SizeBytes = table.Column(type: "bigint", nullable: true),
Sha256 = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
ErrorCode = table.Column(type: "character varying(100)", maxLength: 100, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DeviceSupportBundles", x => x.Id);
table.ForeignKey(
name: "FK_DeviceSupportBundles_Devices_DeviceId",
column: x => x.DeviceId,
principalTable: "Devices",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DeviceSupportBundles_Tenants_TenantId",
column: x => x.TenantId,
principalTable: "Tenants",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.CheckConstraint(
name: "CK_DeviceSupportBundles_Status",
sql: "\"Status\" IN ('PendingDispatch', 'Collecting', 'Available', 'Failed', 'TimedOut', 'Expired')");
});
migrationBuilder.CreateIndex(
name: "IX_DeviceSupportBundles_CorrelationId",
table: "DeviceSupportBundles",
column: "CorrelationId");
migrationBuilder.CreateIndex(
name: "IX_DeviceSupportBundles_DeviceId_CreatedAtUtc",
table: "DeviceSupportBundles",
columns: new[] { "DeviceId", "CreatedAtUtc" });
migrationBuilder.CreateIndex(
name: "IX_DeviceSupportBundles_ExpiresAtUtc",
table: "DeviceSupportBundles",
column: "ExpiresAtUtc");
migrationBuilder.CreateIndex(
name: "IX_DeviceSupportBundles_RequestedByUserId_ClientRequestId",
table: "DeviceSupportBundles",
columns: new[] { "RequestedByUserId", "ClientRequestId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_DeviceSupportBundles_Status_NextDispatchAttemptAtUtc",
table: "DeviceSupportBundles",
columns: new[] { "Status", "NextDispatchAttemptAtUtc" });
migrationBuilder.CreateIndex(
name: "IX_DeviceSupportBundles_TenantId_CreatedAtUtc",
table: "DeviceSupportBundles",
columns: new[] { "TenantId", "CreatedAtUtc" });
migrationBuilder.CreateIndex(
name: "UX_DeviceSupportBundles_Device_Active",
table: "DeviceSupportBundles",
column: "DeviceId",
unique: true,
filter: "\"Status\" IN ('PendingDispatch', 'Collecting')");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DeviceSupportBundles");
}
}
}