using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ClassNotify.Server.Data.Migrations
{
///
public partial class AddDeviceCommandsTable : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "DeviceCommands",
columns: table => new
{
Id = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
TenantId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
DeviceId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
CommandType = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
Parameters = table.Column(type: "text", nullable: true),
CreatedBy = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
ExpiresAt = table.Column(type: "timestamp with time zone", nullable: false),
StartedAt = table.Column(type: "timestamp with time zone", nullable: true),
CompletedAt = table.Column(type: "timestamp with time zone", nullable: true),
Status = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
ResultCode = table.Column(type: "integer", nullable: true),
ResultMessage = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DeviceCommands", x => x.Id);
table.ForeignKey(
name: "FK_DeviceCommands_Devices_DeviceId",
column: x => x.DeviceId,
principalTable: "Devices",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DeviceCommands_Tenants_TenantId",
column: x => x.TenantId,
principalTable: "Tenants",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_DeviceCommands_DeviceId_Status",
table: "DeviceCommands",
columns: new[] { "DeviceId", "Status" });
migrationBuilder.CreateIndex(
name: "IX_DeviceCommands_Status_ExpiresAt",
table: "DeviceCommands",
columns: new[] { "Status", "ExpiresAt" });
migrationBuilder.CreateIndex(
name: "IX_DeviceCommands_TenantId_DeviceId_CreatedAt",
table: "DeviceCommands",
columns: new[] { "TenantId", "DeviceId", "CreatedAt" },
descending: new[] { false, false, true });
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DeviceCommands");
}
}
}