using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace AsbCloudDb.Migrations
{
    public partial class Add_GTR : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "t_wits_float",
                columns: table => new
                {
                    id_telemetry = table.Column<int>(type: "integer", nullable: false),
                    id_record = table.Column<int>(type: "integer", nullable: false),
                    id_item = table.Column<int>(type: "integer", nullable: false),
                    date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    value = table.Column<float>(type: "real", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_wits_float", x => new { x.id_telemetry, x.id_record, x.id_item, x.date });
                    table.ForeignKey(
                        name: "FK_t_wits_float_t_telemetry_id_telemetry",
                        column: x => x.id_telemetry,
                        principalTable: "t_telemetry",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "таблица данных ГТИ с типом значения float");

            migrationBuilder.CreateTable(
                name: "t_wits_int",
                columns: table => new
                {
                    id_telemetry = table.Column<int>(type: "integer", nullable: false),
                    id_record = table.Column<int>(type: "integer", nullable: false),
                    id_item = table.Column<int>(type: "integer", nullable: false),
                    date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    value = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_wits_int", x => new { x.id_telemetry, x.id_record, x.id_item, x.date });
                    table.ForeignKey(
                        name: "FK_t_wits_int_t_telemetry_id_telemetry",
                        column: x => x.id_telemetry,
                        principalTable: "t_telemetry",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "таблица данных ГТИ с типом значения int");

            migrationBuilder.CreateTable(
                name: "t_wits_string",
                columns: table => new
                {
                    id_telemetry = table.Column<int>(type: "integer", nullable: false),
                    id_record = table.Column<int>(type: "integer", nullable: false),
                    id_item = table.Column<int>(type: "integer", nullable: false),
                    date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    value = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_t_wits_string", x => new { x.id_telemetry, x.id_record, x.id_item, x.date });
                    table.ForeignKey(
                        name: "FK_t_wits_string_t_telemetry_id_telemetry",
                        column: x => x.id_telemetry,
                        principalTable: "t_telemetry",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "таблица данных ГТИ с типом значения string");

            migrationBuilder.Sql
                ("SELECT create_hypertable('t_wits_string','date','id_telemetry',2,chunk_time_interval => INTERVAL '5 day'); " +
                 "SELECT create_hypertable('t_wits_float','date','id_telemetry',2,chunk_time_interval => INTERVAL '5 day'); " +
                 "SELECT create_hypertable('t_wits_int','date','id_telemetry',2,chunk_time_interval => INTERVAL '5 day'); ");

        }

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

            migrationBuilder.DropTable(
                name: "t_wits_int");

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