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

#nullable disable

namespace AsbCloudDb.Migrations
{
    /// <inheritdoc />
    public partial class Remove_some_processMapsPlan : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "t_process_map_plan_ream");

            migrationBuilder.DropTable(
                name: "t_process_map_plan_rotor_lowering_bit");

            migrationBuilder.DropTable(
                name: "t_process_map_plan_rotor_rpm_acceleration");

            migrationBuilder.DropTable(
                name: "t_process_map_plan_slide_lowering_bit");

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

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "t_process_map_plan_ream",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор")
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    id_author = table.Column<int>(type: "integer", nullable: false, comment: "Автор"),
                    id_editor = table.Column<int>(type: "integer", nullable: true, comment: "Редактор"),
                    id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины"),
                    id_wellsection_type = table.Column<int>(type: "integer", nullable: false, comment: "Тип секции"),
                    creation = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "дата создания"),
                    depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу до, м"),
                    depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу от, м"),
                    id_previous = table.Column<int>(type: "integer", nullable: true, comment: "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная"),
                    id_state = table.Column<int>(type: "integer", nullable: false, comment: "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная"),
                    obsolete = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true, 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_plan_ream", x => x.id);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_ream_t_user_id_author",
                        column: x => x.id_author,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_ream_t_user_id_editor",
                        column: x => x.id_editor,
                        principalTable: "t_user",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_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_plan_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.CreateTable(
                name: "t_process_map_plan_rotor_lowering_bit",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор")
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    id_author = table.Column<int>(type: "integer", nullable: false, comment: "Автор"),
                    id_editor = table.Column<int>(type: "integer", nullable: true, comment: "Редактор"),
                    id_previous = table.Column<int>(type: "integer", nullable: true, comment: "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная"),
                    id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины"),
                    id_wellsection_type = table.Column<int>(type: "integer", nullable: false, comment: "Тип секции"),
                    creation = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "дата создания"),
                    depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу до, м"),
                    depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу от, м"),
                    differential_pressure = table.Column<double>(type: "double precision", nullable: false, comment: "Перепад давления уставка, атм."),
                    flow_rate_down = table.Column<double>(type: "double precision", nullable: false, comment: "Расход вниз, л/с."),
                    id_state = table.Column<int>(type: "integer", nullable: false, comment: "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная"),
                    note = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false, comment: "Примечание"),
                    obsolete = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true, comment: "дата устаревания"),
                    pressure_max = table.Column<double>(type: "double precision", nullable: false, comment: "Максимально допустимое давление, атм."),
                    rop_down = table.Column<double>(type: "double precision", nullable: false, comment: "Скорость вниз, м/ч."),
                    rpm_down = table.Column<double>(type: "double precision", nullable: false, comment: "Обороты вниз, об/мин."),
                    slacking_off = table.Column<double>(type: "double precision", nullable: false, comment: "Посадка, т."),
                    torque_max = table.Column<double>(type: "double precision", nullable: false, comment: "Максимально допустимый момент, кН*м.")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_process_map_plan_rotor_lowering_bit", x => x.id);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_rotor_lowering_bit_t_process_map_plan_ro~",
                        column: x => x.id_previous,
                        principalTable: "t_process_map_plan_rotor_lowering_bit",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_rotor_lowering_bit_t_user_id_author",
                        column: x => x.id_author,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_rotor_lowering_bit_t_user_id_editor",
                        column: x => x.id_editor,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_rotor_lowering_bit_t_well_id_well",
                        column: x => x.id_well,
                        principalTable: "t_well",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_rotor_lowering_bit_t_well_section_type_i~",
                        column: x => x.id_wellsection_type,
                        principalTable: "t_well_section_type",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "РТК подход к забою в роторе");

            migrationBuilder.CreateTable(
                name: "t_process_map_plan_rotor_rpm_acceleration",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор")
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    id_author = table.Column<int>(type: "integer", nullable: false, comment: "Автор"),
                    id_editor = table.Column<int>(type: "integer", nullable: true, comment: "Редактор"),
                    id_previous = table.Column<int>(type: "integer", nullable: true, comment: "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная"),
                    id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины"),
                    id_wellsection_type = table.Column<int>(type: "integer", nullable: false, comment: "Тип секции"),
                    creation = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "дата создания"),
                    depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу до, м"),
                    depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу от, м"),
                    id_state = table.Column<int>(type: "integer", nullable: false, comment: "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная"),
                    note = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false, comment: "Примечание"),
                    obsolete = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true, comment: "дата устаревания"),
                    rpm = table.Column<double>(type: "double precision", nullable: false, comment: "Обороты на ВСП уставка, об/мин."),
                    rpm_max = table.Column<double>(type: "double precision", nullable: false, comment: "Обороты на ВСП ограничение, об/мин."),
                    top_drive_torque = table.Column<double>(type: "double precision", nullable: false, comment: "Момент на ВСП уставка, кН*м."),
                    top_drive_torque_max = table.Column<double>(type: "double precision", nullable: false, comment: "Момент на ВСП ограничение, кН*м.")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_process_map_plan_rotor_rpm_acceleration", x => x.id);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_rotor_rpm_acceleration_t_process_map_pla~",
                        column: x => x.id_previous,
                        principalTable: "t_process_map_plan_rotor_rpm_acceleration",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_rotor_rpm_acceleration_t_user_id_author",
                        column: x => x.id_author,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_rotor_rpm_acceleration_t_user_id_editor",
                        column: x => x.id_editor,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_rotor_rpm_acceleration_t_well_id_well",
                        column: x => x.id_well,
                        principalTable: "t_well",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_rotor_rpm_acceleration_t_well_section_ty~",
                        column: x => x.id_wellsection_type,
                        principalTable: "t_well_section_type",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "Выход на обороты перед ротором");

            migrationBuilder.CreateTable(
                name: "t_process_map_plan_slide_lowering_bit",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор")
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    id_author = table.Column<int>(type: "integer", nullable: false, comment: "Автор"),
                    id_editor = table.Column<int>(type: "integer", nullable: true, comment: "Редактор"),
                    id_previous = table.Column<int>(type: "integer", nullable: true, comment: "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная"),
                    id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины"),
                    id_wellsection_type = table.Column<int>(type: "integer", nullable: false, comment: "Тип секции"),
                    creation = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "дата создания"),
                    depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу до, м"),
                    depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу от, м"),
                    differential_pressure = table.Column<double>(type: "double precision", nullable: false, comment: "Перепад давления уставка, атм."),
                    flow_rate_down = table.Column<double>(type: "double precision", nullable: false, comment: "Расход вниз, л/с."),
                    id_state = table.Column<int>(type: "integer", nullable: false, comment: "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная"),
                    note = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false, comment: "Примечание"),
                    obsolete = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true, comment: "дата устаревания"),
                    pressure_max = table.Column<double>(type: "double precision", nullable: false, comment: "Максимально допустимое давление, атм."),
                    rop_down = table.Column<double>(type: "double precision", nullable: false, comment: "Скорость вниз, м/ч.")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_process_map_plan_slide_lowering_bit", x => x.id);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_slide_lowering_bit_t_process_map_plan_sl~",
                        column: x => x.id_previous,
                        principalTable: "t_process_map_plan_slide_lowering_bit",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_slide_lowering_bit_t_user_id_author",
                        column: x => x.id_author,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_slide_lowering_bit_t_user_id_editor",
                        column: x => x.id_editor,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_slide_lowering_bit_t_well_id_well",
                        column: x => x.id_well,
                        principalTable: "t_well",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_slide_lowering_bit_t_well_section_type_i~",
                        column: x => x.id_wellsection_type,
                        principalTable: "t_well_section_type",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "РТК подход к забою в слайде");

            migrationBuilder.CreateTable(
                name: "t_process_map_plan_updating_noload_parameters",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор")
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    id_author = table.Column<int>(type: "integer", nullable: false, comment: "Автор"),
                    id_editor = table.Column<int>(type: "integer", nullable: true, comment: "Редактор"),
                    id_previous = table.Column<int>(type: "integer", nullable: true, comment: "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная"),
                    id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины"),
                    id_wellsection_type = table.Column<int>(type: "integer", nullable: false, comment: "Тип секции"),
                    creation = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "дата создания"),
                    depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу до, м"),
                    depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу от, м"),
                    id_decline_socket_column = table.Column<bool>(type: "boolean", nullable: false, comment: "СПУСК ОК Да/Нет"),
                    id_state = table.Column<int>(type: "integer", nullable: false, comment: "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная"),
                    note = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false, comment: "Примечание"),
                    obsolete = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true, comment: "дата устаревания")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_process_map_plan_updating_noload_parameters", x => x.id);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_updating_noload_parameters_t_process_map~",
                        column: x => x.id_previous,
                        principalTable: "t_process_map_plan_updating_noload_parameters",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_updating_noload_parameters_t_user_id_aut~",
                        column: x => x.id_author,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_updating_noload_parameters_t_user_id_edi~",
                        column: x => x.id_editor,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_updating_noload_parameters_t_well_id_well",
                        column: x => x.id_well,
                        principalTable: "t_well",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_process_map_plan_updating_noload_parameters_t_well_sectio~",
                        column: x => x.id_wellsection_type,
                        principalTable: "t_well_section_type",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "Обновление холостого хода");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_ream_id_author",
                table: "t_process_map_plan_ream",
                column: "id_author");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_ream_id_editor",
                table: "t_process_map_plan_ream",
                column: "id_editor");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_ream_id_well",
                table: "t_process_map_plan_ream",
                column: "id_well");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_ream_id_wellsection_type",
                table: "t_process_map_plan_ream",
                column: "id_wellsection_type");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_rotor_lowering_bit_id_author",
                table: "t_process_map_plan_rotor_lowering_bit",
                column: "id_author");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_rotor_lowering_bit_id_editor",
                table: "t_process_map_plan_rotor_lowering_bit",
                column: "id_editor");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_rotor_lowering_bit_id_previous",
                table: "t_process_map_plan_rotor_lowering_bit",
                column: "id_previous");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_rotor_lowering_bit_id_well",
                table: "t_process_map_plan_rotor_lowering_bit",
                column: "id_well");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_rotor_lowering_bit_id_wellsection_type",
                table: "t_process_map_plan_rotor_lowering_bit",
                column: "id_wellsection_type");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_rotor_rpm_acceleration_id_author",
                table: "t_process_map_plan_rotor_rpm_acceleration",
                column: "id_author");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_rotor_rpm_acceleration_id_editor",
                table: "t_process_map_plan_rotor_rpm_acceleration",
                column: "id_editor");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_rotor_rpm_acceleration_id_previous",
                table: "t_process_map_plan_rotor_rpm_acceleration",
                column: "id_previous");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_rotor_rpm_acceleration_id_well",
                table: "t_process_map_plan_rotor_rpm_acceleration",
                column: "id_well");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_rotor_rpm_acceleration_id_wellsection_ty~",
                table: "t_process_map_plan_rotor_rpm_acceleration",
                column: "id_wellsection_type");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_slide_lowering_bit_id_author",
                table: "t_process_map_plan_slide_lowering_bit",
                column: "id_author");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_slide_lowering_bit_id_editor",
                table: "t_process_map_plan_slide_lowering_bit",
                column: "id_editor");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_slide_lowering_bit_id_previous",
                table: "t_process_map_plan_slide_lowering_bit",
                column: "id_previous");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_slide_lowering_bit_id_well",
                table: "t_process_map_plan_slide_lowering_bit",
                column: "id_well");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_slide_lowering_bit_id_wellsection_type",
                table: "t_process_map_plan_slide_lowering_bit",
                column: "id_wellsection_type");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_updating_noload_parameters_id_author",
                table: "t_process_map_plan_updating_noload_parameters",
                column: "id_author");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_updating_noload_parameters_id_editor",
                table: "t_process_map_plan_updating_noload_parameters",
                column: "id_editor");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_updating_noload_parameters_id_previous",
                table: "t_process_map_plan_updating_noload_parameters",
                column: "id_previous");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_updating_noload_parameters_id_well",
                table: "t_process_map_plan_updating_noload_parameters",
                column: "id_well");

            migrationBuilder.CreateIndex(
                name: "IX_t_process_map_plan_updating_noload_parameters_id_wellsectio~",
                table: "t_process_map_plan_updating_noload_parameters",
                column: "id_wellsection_type");
        }
    }
}