persistence/DD.Persistence.Database.Postgres/Migrations/20250203061429_Init.cs

159 lines
8.2 KiB
C#
Raw Normal View History

2024-12-18 16:00:51 +05:00
using System;
2025-01-22 16:13:56 +05:00
using System.Text.Json;
2024-12-18 16:00:51 +05:00
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",
2024-12-18 16:00:51 +05:00
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 заменяющей записи"),
Value = table.Column<string>(type: "jsonb", nullable: false, comment: "Значение")
},
constraints: table =>
{
table.PrimaryKey("PK_change_log", x => x.Id);
2024-12-18 16:00:51 +05:00
});
migrationBuilder.CreateTable(
name: "data_scheme",
2024-12-18 16:00:51 +05:00
columns: table => new
{
2025-01-22 16:13:56 +05:00
DiscriminatorId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Идентификатор схемы данных"),
PropNames = table.Column<string>(type: "jsonb", nullable: false, comment: "Наименования полей в порядке индексации")
2024-12-18 16:00:51 +05:00
},
constraints: table =>
{
table.PrimaryKey("PK_data_scheme", x => x.DiscriminatorId);
2024-12-18 16:00:51 +05:00
});
migrationBuilder.CreateTable(
name: "data_source_system",
2024-12-18 16:00:51 +05:00
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);
2024-12-18 16:00:51 +05:00
});
migrationBuilder.CreateTable(
name: "parameter_data",
2024-12-18 16:00:51 +05:00
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 });
2024-12-18 16:00:51 +05:00
});
migrationBuilder.CreateTable(
name: "setpoint",
2024-12-18 16:00:51 +05:00
columns: table => new
{
Key = table.Column<Guid>(type: "uuid", nullable: false, comment: "Ключ"),
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата создания уставки"),
2025-01-22 16:13:56 +05:00
Value = table.Column<JsonElement>(type: "jsonb", nullable: false, comment: "Значение уставки"),
2024-12-18 16:00:51 +05:00
IdUser = table.Column<Guid>(type: "uuid", nullable: false, comment: "Id автора последнего изменения")
},
constraints: table =>
{
table.PrimaryKey("PK_setpoint", x => new { x.Key, x.Timestamp });
2024-12-18 16:00:51 +05:00
});
migrationBuilder.CreateTable(
name: "timestamped_values",
2024-12-18 16:00:51 +05:00
columns: table => new
{
2025-01-22 16:13:56 +05:00
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Временная отметка"),
DiscriminatorId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Дискриминатор системы"),
2025-01-22 16:13:56 +05:00
Values = table.Column<string>(type: "jsonb", nullable: false, comment: "Данные")
2024-12-18 16:00:51 +05:00
},
constraints: table =>
{
table.PrimaryKey("PK_timestamped_values", x => new { x.DiscriminatorId, x.Timestamp });
2025-01-22 16:13:56 +05:00
table.ForeignKey(
name: "FK_timestamped_values_data_scheme_DiscriminatorId",
2025-01-22 16:13:56 +05:00
column: x => x.DiscriminatorId,
principalTable: "data_scheme",
2025-01-22 16:13:56 +05:00
principalColumn: "DiscriminatorId",
onDelete: ReferentialAction.Cascade);
});
2024-12-18 16:00:51 +05:00
migrationBuilder.CreateTable(
name: "tech_message",
2024-12-18 16:00:51 +05:00
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);
2024-12-18 16:00:51 +05:00
table.ForeignKey(
name: "FK_tech_message_data_source_system_SystemId",
2024-12-18 16:00:51 +05:00
column: x => x.SystemId,
principalTable: "data_source_system",
2024-12-18 16:00:51 +05:00
principalColumn: "SystemId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_tech_message_SystemId",
table: "tech_message",
2024-12-18 16:00:51 +05:00
column: "SystemId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "change_log");
2024-12-18 16:00:51 +05:00
migrationBuilder.DropTable(
name: "parameter_data");
2024-12-18 16:00:51 +05:00
migrationBuilder.DropTable(
name: "setpoint");
2024-12-18 16:00:51 +05:00
migrationBuilder.DropTable(
name: "tech_message");
2024-12-18 16:00:51 +05:00
migrationBuilder.DropTable(
name: "timestamped_values");
2024-12-18 16:00:51 +05:00
migrationBuilder.DropTable(
name: "data_source_system");
migrationBuilder.DropTable(
name: "data_scheme");
2024-12-18 16:00:51 +05:00
}
}
}