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

#nullable disable

namespace AsbCloudDb.Migrations
{
    public partial class AddTable_t_faq : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "t_faq",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор")
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    id_well = table.Column<int>(type: "integer", nullable: false, comment: "id скважины"),
                    id_author_question = table.Column<int>(type: "integer", nullable: false, comment: "id автора вопроса"),
                    id_author_answer = table.Column<int>(type: "integer", nullable: false, comment: "id автора ответа"),
                    date_created_question = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата создания вопроса"),
                    date_answer = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true, comment: "Дата ответа"),
                    date_last_edited_question = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата последнего редактирования вопроса"),
                    question = table.Column<string>(type: "text", nullable: false, comment: "Текст вопроса"),
                    answer = table.Column<string>(type: "text", nullable: false, comment: "Текст ответа"),
                    state = table.Column<int>(type: "integer", nullable: false, comment: "Статус вопроса"),
                    counter_question = table.Column<int>(type: "integer", nullable: false, comment: "Счетчик повторений вопроса"),
                    id_replacement_question = table.Column<int>(type: "integer", nullable: true, comment: "Ключ заменяющего вопроса"),
                    is_frequently_question = table.Column<bool>(type: "boolean", nullable: false, comment: "Частый вопрос")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_faq", x => x.id);
                    table.ForeignKey(
                        name: "FK_t_faq_t_user_id_author_answer",
                        column: x => x.id_author_answer,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_faq_t_user_id_author_question",
                        column: x => x.id_author_question,
                        principalTable: "t_user",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_t_faq_t_well_id_well",
                        column: x => x.id_well,
                        principalTable: "t_well",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "вопросы пользователей");

            migrationBuilder.CreateIndex(
                name: "IX_t_faq_id_author_answer",
                table: "t_faq",
                column: "id_author_answer");

            migrationBuilder.CreateIndex(
                name: "IX_t_faq_id_author_question",
                table: "t_faq",
                column: "id_author_question");

            migrationBuilder.CreateIndex(
                name: "IX_t_faq_id_well",
                table: "t_faq",
                column: "id_well");
        }

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