176 lines
10 KiB
C#
176 lines
10 KiB
C#
using System;
|
||
using Microsoft.EntityFrameworkCore.Migrations;
|
||
|
||
#nullable disable
|
||
|
||
namespace DD.Persistence.Database.Postgres.Migrations
|
||
{
|
||
/// <inheritdoc />
|
||
public partial class Init : Migration
|
||
{
|
||
/// <inheritdoc />
|
||
protected override void Up(MigrationBuilder migrationBuilder)
|
||
{
|
||
migrationBuilder.CreateTable(
|
||
name: "change_log",
|
||
columns: table => new
|
||
{
|
||
Id = table.Column<Guid>(type: "uuid", nullable: false, comment: "Ключ записи"),
|
||
IdDiscriminator = table.Column<Guid>(type: "uuid", nullable: false, comment: "Дискриминатор таблицы"),
|
||
IdAuthor = table.Column<Guid>(type: "uuid", nullable: false, comment: "Автор изменения"),
|
||
IdEditor = table.Column<Guid>(type: "uuid", nullable: true, comment: "Редактор"),
|
||
Creation = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата создания записи"),
|
||
Obsolete = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true, comment: "Дата устаревания (например при удалении)"),
|
||
IdNext = table.Column<Guid>(type: "uuid", nullable: true, comment: "Id заменяющей записи"),
|
||
DepthStart = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина забоя на дату начала интервала"),
|
||
DepthEnd = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина забоя на дату окончания интервала"),
|
||
IdSection = table.Column<Guid>(type: "uuid", nullable: false, comment: "Ключ секции"),
|
||
Value = table.Column<string>(type: "jsonb", nullable: false, comment: "Значение")
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("PK_change_log", x => x.Id);
|
||
});
|
||
|
||
migrationBuilder.CreateTable(
|
||
name: "data_saub",
|
||
columns: table => new
|
||
{
|
||
date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||
mode = table.Column<int>(type: "integer", nullable: true),
|
||
user = table.Column<string>(type: "text", nullable: true),
|
||
wellDepth = table.Column<double>(type: "double precision", nullable: true),
|
||
bitDepth = table.Column<double>(type: "double precision", nullable: true),
|
||
blockPosition = table.Column<double>(type: "double precision", nullable: true),
|
||
blockSpeed = table.Column<double>(type: "double precision", nullable: true),
|
||
pressure = table.Column<double>(type: "double precision", nullable: true),
|
||
axialLoad = table.Column<double>(type: "double precision", nullable: true),
|
||
hookWeight = table.Column<double>(type: "double precision", nullable: true),
|
||
rotorTorque = table.Column<double>(type: "double precision", nullable: true),
|
||
rotorSpeed = table.Column<double>(type: "double precision", nullable: true),
|
||
flow = table.Column<double>(type: "double precision", nullable: true),
|
||
mseState = table.Column<short>(type: "smallint", nullable: false),
|
||
idFeedRegulator = table.Column<int>(type: "integer", nullable: false),
|
||
mse = table.Column<double>(type: "double precision", nullable: true),
|
||
pump0Flow = table.Column<double>(type: "double precision", nullable: true),
|
||
pump1Flow = table.Column<double>(type: "double precision", nullable: true),
|
||
pump2Flow = table.Column<double>(type: "double precision", nullable: true)
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("PK_data_saub", x => x.date);
|
||
});
|
||
|
||
migrationBuilder.CreateTable(
|
||
name: "data_source_system",
|
||
columns: table => new
|
||
{
|
||
SystemId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Id системы - источника данных"),
|
||
Name = table.Column<string>(type: "varchar(256)", nullable: false, comment: "Наименование системы - источника данных"),
|
||
Description = table.Column<string>(type: "text", nullable: true, comment: "Описание системы - источника данных")
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("PK_data_source_system", x => x.SystemId);
|
||
});
|
||
|
||
migrationBuilder.CreateTable(
|
||
name: "parameter_data",
|
||
columns: table => new
|
||
{
|
||
DiscriminatorId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Дискриминатор системы"),
|
||
ParameterId = table.Column<int>(type: "integer", nullable: false, comment: "Id параметра"),
|
||
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Временная отметка"),
|
||
Value = table.Column<string>(type: "varchar(256)", nullable: false, comment: "Значение параметра в виде строки")
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("PK_parameter_data", x => new { x.DiscriminatorId, x.ParameterId, x.Timestamp });
|
||
});
|
||
|
||
migrationBuilder.CreateTable(
|
||
name: "setpoint",
|
||
columns: table => new
|
||
{
|
||
Key = table.Column<Guid>(type: "uuid", nullable: false, comment: "Ключ"),
|
||
Created = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата создания уставки"),
|
||
Value = table.Column<object>(type: "jsonb", nullable: false, comment: "Значение уставки"),
|
||
IdUser = table.Column<Guid>(type: "uuid", nullable: false, comment: "Id автора последнего изменения")
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("PK_setpoint", x => new { x.Key, x.Created });
|
||
});
|
||
|
||
migrationBuilder.CreateTable(
|
||
name: "timestamped_set",
|
||
columns: table => new
|
||
{
|
||
IdDiscriminator = table.Column<Guid>(type: "uuid", nullable: false, comment: "Дискриминатор ссылка на тип сохраняемых данных"),
|
||
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Отметка времени, строго в UTC"),
|
||
Set = table.Column<string>(type: "jsonb", nullable: false, comment: "Набор сохраняемых данных")
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("PK_timestamped_set", x => new { x.IdDiscriminator, x.Timestamp });
|
||
},
|
||
comment: "Общая таблица данных временных рядов");
|
||
|
||
migrationBuilder.CreateTable(
|
||
name: "tech_message",
|
||
columns: table => new
|
||
{
|
||
EventId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Id события"),
|
||
CategoryId = table.Column<int>(type: "integer", nullable: false, comment: "Id Категории важности"),
|
||
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата возникновения"),
|
||
Text = table.Column<string>(type: "varchar(512)", nullable: false, comment: "Текст сообщения"),
|
||
SystemId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Id системы, к которой относится сообщение"),
|
||
EventState = table.Column<int>(type: "integer", nullable: false, comment: "Статус события")
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("PK_tech_message", x => x.EventId);
|
||
table.ForeignKey(
|
||
name: "FK_tech_message_data_source_system_SystemId",
|
||
column: x => x.SystemId,
|
||
principalTable: "data_source_system",
|
||
principalColumn: "SystemId",
|
||
onDelete: ReferentialAction.Cascade);
|
||
});
|
||
|
||
migrationBuilder.CreateIndex(
|
||
name: "IX_tech_message_SystemId",
|
||
table: "tech_message",
|
||
column: "SystemId");
|
||
|
||
migrationBuilder.Sql
|
||
("SELECT create_hypertable('parameter_data','Timestamp','ParameterId',2,chunk_time_interval => INTERVAL '5 day');");
|
||
}
|
||
|
||
/// <inheritdoc />
|
||
protected override void Down(MigrationBuilder migrationBuilder)
|
||
{
|
||
migrationBuilder.DropTable(
|
||
name: "change_log");
|
||
|
||
migrationBuilder.DropTable(
|
||
name: "data_saub");
|
||
|
||
migrationBuilder.DropTable(
|
||
name: "parameter_data");
|
||
|
||
migrationBuilder.DropTable(
|
||
name: "setpoint");
|
||
|
||
migrationBuilder.DropTable(
|
||
name: "tech_message");
|
||
|
||
migrationBuilder.DropTable(
|
||
name: "timestamped_set");
|
||
|
||
migrationBuilder.DropTable(
|
||
name: "data_source_system");
|
||
}
|
||
}
|
||
}
|