using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace AsbCloudDb.Migrations
{
    public partial class Add_Table_DataSaubStat : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "t_data_saub_stat",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    date_start = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата и время начала"),
                    date_end = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата и время окончания"),
                    depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина забоя по стволу начальная"),
                    depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина забоя по стволу конечная"),
                    speed = table.Column<double>(type: "double precision", nullable: false, comment: "Скорость бурения"),
                    block_speed_sp = table.Column<double>(type: "double precision", nullable: true, comment: "Ограничение скорости блока"),
                    pressure = table.Column<double>(type: "double precision", nullable: false, comment: "Давление"),
                    pressure_idle = table.Column<double>(type: "double precision", nullable: true, comment: "Давление холостого хода"),
                    pressure_sp = table.Column<double>(type: "double precision", nullable: true, comment: "Ограничение фактического давления"),
                    axial_load = table.Column<double>(type: "double precision", nullable: false, comment: "Фактическая нагрузка"),
                    axial_load_sp = table.Column<double>(type: "double precision", nullable: true, comment: "Ограничение факт. нагрузки"),
                    axial_load_limit_max = table.Column<double>(type: "double precision", nullable: true, comment: "Максимально допустимая нагрузка"),
                    rotor_torque = table.Column<double>(type: "double precision", nullable: false, comment: "Фактический момент"),
                    rotor_torque_sp = table.Column<double>(type: "double precision", nullable: true, comment: "Ограничение факт. момента"),
                    rotor_torque_limit_max = table.Column<double>(type: "double precision", nullable: true, comment: "Максимально допустимый момент"),
                    id_feed_regulator = table.Column<short>(type: "smallint", nullable: true, comment: "Работа при достижении ограничения"),
                    rotor_speed = table.Column<double>(type: "double precision", nullable: false, comment: "Фактическая скорость оборотов ВСП"),
                    id_category = table.Column<int>(type: "integer", nullable: false, comment: "Название автоопределённой операции"),
                    enabled_subsystems = table.Column<int>(type: "integer", nullable: false, comment: "Флаги подсистем"),
                    has_oscillation = table.Column<bool>(type: "boolean", nullable: false, comment: "Наличие или отсутствие осцилляции"),
                    flow = table.Column<double>(type: "double precision", nullable: false, comment: "Фактический расход"),
                    id_telemetry = table.Column<int>(type: "integer", nullable: false, comment: "Ключ телеметрии")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_data_saub_stat", x => x.id);
                    table.ForeignKey(
                        name: "FK_t_data_saub_stat_t_telemetry_id_telemetry",
                        column: x => x.id_telemetry,
                        principalTable: "t_telemetry",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_data_saub_stat_t_well_operation_category_id_category",
                        column: x => x.id_category,
                        principalTable: "t_well_operation_category",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "Кеш-таблица для хранения данных для РТК-отчета");

            migrationBuilder.CreateIndex(
                name: "IX_t_data_saub_stat_id_category",
                table: "t_data_saub_stat",
                column: "id_category");

            migrationBuilder.CreateIndex(
                name: "IX_t_data_saub_stat_id_telemetry",
                table: "t_data_saub_stat",
                column: "id_telemetry");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "t_data_saub_stat");
        }
    }
}