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

namespace AsbCloudDb.Migrations
{
    public partial class Rename_DrillingParam_Consumption_to_Flow : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<double>(
                name: "depth_start",
                table: "t_well_operation",
                type: "double precision",
                nullable: false,
                comment: "Глубина на начало операции, м",
                oldClrType: typeof(double),
                oldType: "double precision",
                oldComment: "Глубина забоя на начало операции, м");

            migrationBuilder.AlterColumn<double>(
                name: "depth_end",
                table: "t_well_operation",
                type: "double precision",
                nullable: false,
                comment: "Глубина после завершения операции, м",
                oldClrType: typeof(double),
                oldType: "double precision",
                oldComment: "Глубина забоя после завершения операции, м");

            migrationBuilder.CreateTable(
                name: "t_drill_params",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    well_id = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины"),
                    depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Стартовая глубина"),
                    depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина окончания интервала"),
                    id_wellsection_type = table.Column<int>(type: "integer", nullable: false, comment: "Id с типом секции скважины"),
                    axial_load_min = table.Column<double>(type: "double precision", nullable: false, comment: "Минимальная нагрузка"),
                    axial_load_avg = table.Column<double>(type: "double precision", nullable: false, comment: "Средняя нагрузка"),
                    axial_load_max = table.Column<double>(type: "double precision", nullable: false, comment: "Максимальная нагрузка"),
                    pressure_min = table.Column<double>(type: "double precision", nullable: false, comment: "Минимальное давление"),
                    pressure_avg = table.Column<double>(type: "double precision", nullable: false, comment: "Среднее давление"),
                    pressure_max = table.Column<double>(type: "double precision", nullable: false, comment: "Максимальное давление"),
                    top_drive_min = table.Column<double>(type: "double precision", nullable: false, comment: "Минимальный момент на ВСП"),
                    top_drive_avg = table.Column<double>(type: "double precision", nullable: false, comment: "Средний момент на ВСП"),
                    top_drive_max = table.Column<double>(type: "double precision", nullable: false, comment: "Максимальный момент на ВСП"),
                    top_drive_speed_min = table.Column<double>(type: "double precision", nullable: false, comment: "Минимальные обороты на ВСП"),
                    top_drive_speed_avg = table.Column<double>(type: "double precision", nullable: false, comment: "Средние обороты на ВСП"),
                    top_drive_speed_max = table.Column<double>(type: "double precision", nullable: false, comment: "Максимальные обороты на ВСП"),
                    flow_min = table.Column<double>(type: "double precision", nullable: false, comment: "Минимальный расход"),
                    flow_avg = table.Column<double>(type: "double precision", nullable: false, comment: "Средний расход"),
                    flow_max = table.Column<double>(type: "double precision", nullable: false, comment: "Максимальный расход")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_drill_params", x => x.id);
                    table.ForeignKey(
                        name: "FK_t_drill_params_t_well_well_id",
                        column: x => x.well_id,
                        principalTable: "t_well",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "t_drill_params_t_well_section_type_id_fk",
                        column: x => x.id_wellsection_type,
                        principalTable: "t_well_section_type",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "Режим бурения в секции (диапазоны параметров бурения)");

            migrationBuilder.CreateIndex(
                name: "IX_t_drill_params_id_wellsection_type",
                table: "t_drill_params",
                column: "id_wellsection_type");

            migrationBuilder.CreateIndex(
                name: "IX_t_drill_params_well_id",
                table: "t_drill_params",
                column: "well_id");
        }

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

            migrationBuilder.AlterColumn<double>(
                name: "depth_start",
                table: "t_well_operation",
                type: "double precision",
                nullable: false,
                comment: "Глубина забоя на начало операции, м",
                oldClrType: typeof(double),
                oldType: "double precision",
                oldComment: "Глубина на начало операции, м");

            migrationBuilder.AlterColumn<double>(
                name: "depth_end",
                table: "t_well_operation",
                type: "double precision",
                nullable: false,
                comment: "Глубина забоя после завершения операции, м",
                oldClrType: typeof(double),
                oldType: "double precision",
                oldComment: "Глубина после завершения операции, м");
        }
    }
}