using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Migrations
{
    /// <inheritdoc />
    public partial class AddKpiRollupHourlyTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "KpiRollupHourly",
                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),
                    HourStartUtc = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Value = table.Column<double>(type: "float", nullable: false),
                    MinValue = table.Column<double>(type: "float", nullable: false),
                    MaxValue = table.Column<double>(type: "float", nullable: false),
                    SampleCount = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_KpiRollupHourly", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_KpiRollupHourly_Hour",
                table: "KpiRollupHourly",
                column: "HourStartUtc");

            migrationBuilder.CreateIndex(
                name: "IX_KpiRollupHourly_Series",
                table: "KpiRollupHourly",
                columns: new[] { "Source", "Metric", "Scope", "ScopeKey", "HourStartUtc" },
                unique: true);
        }

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