using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Migrations
{
    /// <inheritdoc />
    public partial class AddKpiSampleTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "KpiSample",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Source = table.Column<string>(type: "varchar(64)", unicode: false, maxLength: 64, nullable: false),
                    Metric = table.Column<string>(type: "varchar(64)", unicode: false, maxLength: 64, nullable: false),
                    Scope = table.Column<string>(type: "varchar(16)", unicode: false, maxLength: 16, nullable: false),
                    ScopeKey = table.Column<string>(type: "varchar(64)", unicode: false, maxLength: 64, nullable: true),
                    Value = table.Column<double>(type: "float", nullable: false),
                    CapturedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpiSample", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_KpiSample_Captured",
                table: "KpiSample",
                column: "CapturedAtUtc");

            migrationBuilder.CreateIndex(
                name: "IX_KpiSample_Series",
                table: "KpiSample",
                columns: new[] { "Source", "Metric", "Scope", "ScopeKey", "CapturedAtUtc" });
        }

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