20260521093000_AddAlarmLogs.cs 3.84 KB
using System;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Rcs.Infrastructure.DB.MsSql;

#nullable disable

namespace Rcs.Infrastructure.Migrations
{
    /// <inheritdoc />
    [DbContext(typeof(AppDbContext))]
    [Migration("20260521093000_AddAlarmLogs")]
    public partial class AddAlarmLogs : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "alarm_logs",
                columns: table => new
                {
                    alarm_log_id = table.Column<Guid>(type: "uuid", nullable: false),
                    alarm_code = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
                    alarm_type = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    level = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
                    source_type = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    source_code = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
                    source_name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
                    title = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
                    message = table.Column<string>(type: "text", nullable: false),
                    details = table.Column<string>(type: "text", nullable: true),
                    extra_data = table.Column<string>(type: "text", nullable: true),
                    is_acknowledged = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    acknowledged_by = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
                    acknowledge_remark = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
                    acknowledged_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    occurred_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    resolved_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    created_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    updated_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_alarm_logs", x => x.alarm_log_id);
                });

            migrationBuilder.CreateIndex(
                name: "idx_alarm_logs_alarm_code",
                table: "alarm_logs",
                column: "alarm_code");

            migrationBuilder.CreateIndex(
                name: "idx_alarm_logs_is_acknowledged",
                table: "alarm_logs",
                column: "is_acknowledged");

            migrationBuilder.CreateIndex(
                name: "idx_alarm_logs_level",
                table: "alarm_logs",
                column: "level");

            migrationBuilder.CreateIndex(
                name: "idx_alarm_logs_occurred_at",
                table: "alarm_logs",
                column: "occurred_at");

            migrationBuilder.CreateIndex(
                name: "idx_alarm_logs_source_code",
                table: "alarm_logs",
                column: "source_code");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "alarm_logs");
        }
    }
}