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

#nullable disable

namespace AsbCloudDb.Migrations
{
    public partial class Remove_old_ProcessMapPlans : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "t_process_map_well_drilling");

            migrationBuilder.DropTable(
                name: "t_process_map_well_ream");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "t_process_map_well_drilling",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    id_user = table.Column<int>(type: "integer", nullable: false, comment: "Id пользователя"),
                    id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины"),
                    id_wellsection_type = table.Column<int>(type: "integer", nullable: false, comment: "Тип секции"),
                    axial_load_limit_max = table.Column<double>(type: "double precision", nullable: false, comment: "Нагрузка, допустимый максимум"),
                    axial_load_plan = table.Column<double>(type: "double precision", nullable: false, comment: "Нагрузка, план"),
                    comment = table.Column<string>(type: "text", nullable: true, comment: "Комментарий"),
                    depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу до, м"),
                    depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу от, м"),
                    flow_limit_max = table.Column<double>(type: "double precision", nullable: false, comment: "Расход, допустимый максимум"),
                    flow_plan = table.Column<double>(type: "double precision", nullable: false, comment: "Расход, план"),
                    id_mode = table.Column<int>(type: "integer", nullable: false, comment: "Id режима (1- ротор, 2 слайд)"),
                    last_update = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата последнего изменения"),
                    pressure_limit_max = table.Column<double>(type: "double precision", nullable: false, comment: "Перепад давления, допустимый максимум"),
                    pressure_plan = table.Column<double>(type: "double precision", nullable: false, comment: "Перепад давления, план"),
                    rop_plan = table.Column<double>(type: "double precision", nullable: false, comment: "Плановая механическая скорость, м/ч"),
                    top_drive_speed_limit_max = table.Column<double>(type: "double precision", nullable: false, comment: "Обороты на ВСП, допустимый максимум"),
                    top_drive_speed_plan = table.Column<double>(type: "double precision", nullable: false, comment: "Обороты на ВСП, план"),
                    top_drive_torque_limit_max = table.Column<double>(type: "double precision", nullable: false, comment: "Момент на ВСП, допустимый максимум"),
                    top_drive_torque_plan = table.Column<double>(type: "double precision", nullable: false, comment: "Момент на ВСП, план"),
                    usage_saub = table.Column<double>(type: "double precision", nullable: false, comment: "Плановый процент использования АКБ"),
                    usage_spin = table.Column<double>(type: "double precision", nullable: false, comment: "Плановый процент использования spin master")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_process_map_well_drilling", x => x.id);
                    table.ForeignKey(
                        name: "FK_t_process_map_well_drilling_t_user_id_user",
                        column: x => x.id_user,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_process_map_well_drilling_t_well_id_well",
                        column: x => x.id_well,
                        principalTable: "t_well",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_process_map_well_drilling_t_well_section_type_id_wellsect~",
                        column: x => x.id_wellsection_type,
                        principalTable: "t_well_section_type",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "РТК бурение скважины");

            migrationBuilder.CreateTable(
                name: "t_process_map_well_ream",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    id_user = table.Column<int>(type: "integer", nullable: false, comment: "Id пользователя"),
                    id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины"),
                    id_wellsection_type = table.Column<int>(type: "integer", nullable: false, comment: "Тип секции"),
                    comment = table.Column<string>(type: "text", nullable: true, comment: "Комментарий"),
                    depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу до, м"),
                    depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу от, м"),
                    last_update = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата последнего изменения"),
                    pressure = table.Column<double>(type: "double precision", nullable: false, comment: "Давление, атм"),
                    repeats = table.Column<double>(type: "double precision", nullable: false, comment: "Количество повторений"),
                    setpoint_drag = table.Column<double>(type: "double precision", nullable: false, comment: "Уставка зятяжки, т"),
                    setpoint_tight = table.Column<double>(type: "double precision", nullable: false, comment: "Уставка посадки, т"),
                    speed_downward = table.Column<double>(type: "double precision", nullable: false, comment: "Скорость спуска, м/ч"),
                    speed_upward = table.Column<double>(type: "double precision", nullable: false, comment: "Скорость подъёма, м/ч"),
                    spin_downward = table.Column<double>(type: "double precision", nullable: false, comment: "Вращение при движении вниз, об/мин"),
                    spin_upward = table.Column<double>(type: "double precision", nullable: false, comment: "Вращение при движении вверх, об/мин"),
                    torque = table.Column<double>(type: "double precision", nullable: false, comment: "Момент, кН*м")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_process_map_well_ream", x => x.id);
                    table.ForeignKey(
                        name: "FK_t_process_map_well_ream_t_user_id_user",
                        column: x => x.id_user,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_process_map_well_ream_t_well_id_well",
                        column: x => x.id_well,
                        principalTable: "t_well",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_process_map_well_ream_t_well_section_type_id_wellsection_~",
                        column: x => x.id_wellsection_type,
                        principalTable: "t_well_section_type",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "РТК проработка скважины");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_well_drilling_id_user",
                table: "t_process_map_well_drilling",
                column: "id_user");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_well_drilling_id_well",
                table: "t_process_map_well_drilling",
                column: "id_well");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_well_drilling_id_wellsection_type",
                table: "t_process_map_well_drilling",
                column: "id_wellsection_type");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_well_ream_id_user",
                table: "t_process_map_well_ream",
                column: "id_user");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_well_ream_id_well",
                table: "t_process_map_well_ream",
                column: "id_well");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_well_ream_id_wellsection_type",
                table: "t_process_map_well_ream",
                column: "id_wellsection_type");
        }
    }
}