This commit is contained in:
parent
3262201973
commit
4af65e258b
@ -1,5 +1,6 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using DD.Persistence.Database.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
@ -12,7 +13,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace DD.Persistence.Database.Postgres.Migrations
|
||||
{
|
||||
[DbContext(typeof(PersistencePostgresContext))]
|
||||
[Migration("20250116093615_Init")]
|
||||
[Migration("20250122111321_Init")]
|
||||
partial class Init
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -25,6 +26,23 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DD.Persistence.Database.Entity.DataScheme", b =>
|
||||
{
|
||||
b.Property<Guid>("DiscriminatorId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasComment("Идентификатор схемы данных");
|
||||
|
||||
b.Property<string>("PropNames")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasComment("Наименования полей в порядке индексации");
|
||||
|
||||
b.HasKey("DiscriminatorId");
|
||||
|
||||
b.ToTable("DataSchemes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DD.Persistence.Database.Entity.DataSourceSystem", b =>
|
||||
{
|
||||
b.Property<Guid>("SystemId")
|
||||
@ -125,23 +143,6 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
b.ToTable("TimestampedValues");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DD.Persistence.Database.Entity.ValuesIdentity", b =>
|
||||
{
|
||||
b.Property<Guid>("DiscriminatorId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasComment("Дискриминатор системы");
|
||||
|
||||
b.Property<string[]>("Identity")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasComment("Идентификаторы");
|
||||
|
||||
b.HasKey("DiscriminatorId");
|
||||
|
||||
b.ToTable("ValuesIdentities");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DD.Persistence.Database.Model.ChangeLog", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@ -209,8 +210,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
.HasColumnType("uuid")
|
||||
.HasComment("Id автора последнего изменения");
|
||||
|
||||
b.Property<object>("Value")
|
||||
.IsRequired()
|
||||
b.Property<JsonElement>("Value")
|
||||
.HasColumnType("jsonb")
|
||||
.HasComment("Значение уставки");
|
||||
|
||||
@ -232,13 +232,13 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
|
||||
modelBuilder.Entity("DD.Persistence.Database.Entity.TimestampedValues", b =>
|
||||
{
|
||||
b.HasOne("DD.Persistence.Database.Entity.ValuesIdentity", "ValuesIdentity")
|
||||
b.HasOne("DD.Persistence.Database.Entity.DataScheme", "DataScheme")
|
||||
.WithMany()
|
||||
.HasForeignKey("DiscriminatorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("ValuesIdentity");
|
||||
b.Navigation("DataScheme");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
@ -32,6 +33,18 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
table.PrimaryKey("PK_ChangeLog", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "DataSchemes",
|
||||
columns: table => new
|
||||
{
|
||||
DiscriminatorId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Идентификатор схемы данных"),
|
||||
PropNames = table.Column<string>(type: "jsonb", nullable: false, comment: "Наименования полей в порядке индексации")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_DataSchemes", x => x.DiscriminatorId);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "DataSourceSystem",
|
||||
columns: table => new
|
||||
@ -65,7 +78,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
{
|
||||
Key = table.Column<Guid>(type: "uuid", nullable: false, comment: "Ключ"),
|
||||
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата создания уставки"),
|
||||
Value = table.Column<object>(type: "jsonb", nullable: false, comment: "Значение уставки"),
|
||||
Value = table.Column<JsonElement>(type: "jsonb", nullable: false, comment: "Значение уставки"),
|
||||
IdUser = table.Column<Guid>(type: "uuid", nullable: false, comment: "Id автора последнего изменения")
|
||||
},
|
||||
constraints: table =>
|
||||
@ -74,15 +87,22 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ValuesIdentities",
|
||||
name: "TimestampedValues",
|
||||
columns: table => new
|
||||
{
|
||||
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Временная отметка"),
|
||||
DiscriminatorId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Дискриминатор системы"),
|
||||
Identity = table.Column<string[]>(type: "jsonb", nullable: false, comment: "Идентификаторы")
|
||||
Values = table.Column<string>(type: "jsonb", nullable: false, comment: "Данные")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ValuesIdentities", x => x.DiscriminatorId);
|
||||
table.PrimaryKey("PK_TimestampedValues", x => new { x.DiscriminatorId, x.Timestamp });
|
||||
table.ForeignKey(
|
||||
name: "FK_TimestampedValues_DataSchemes_DiscriminatorId",
|
||||
column: x => x.DiscriminatorId,
|
||||
principalTable: "DataSchemes",
|
||||
principalColumn: "DiscriminatorId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
@ -107,25 +127,6 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "TimestampedValues",
|
||||
columns: table => new
|
||||
{
|
||||
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Временная отметка"),
|
||||
DiscriminatorId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Дискриминатор системы"),
|
||||
Values = table.Column<string>(type: "jsonb", nullable: false, comment: "Данные")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_TimestampedValues", x => new { x.DiscriminatorId, x.Timestamp });
|
||||
table.ForeignKey(
|
||||
name: "FK_TimestampedValues_ValuesIdentities_DiscriminatorId",
|
||||
column: x => x.DiscriminatorId,
|
||||
principalTable: "ValuesIdentities",
|
||||
principalColumn: "DiscriminatorId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_TechMessage_SystemId",
|
||||
table: "TechMessage",
|
||||
@ -154,7 +155,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
name: "DataSourceSystem");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ValuesIdentities");
|
||||
name: "DataSchemes");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using DD.Persistence.Database.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
@ -22,6 +23,23 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DD.Persistence.Database.Entity.DataScheme", b =>
|
||||
{
|
||||
b.Property<Guid>("DiscriminatorId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasComment("Идентификатор схемы данных");
|
||||
|
||||
b.Property<string>("PropNames")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasComment("Наименования полей в порядке индексации");
|
||||
|
||||
b.HasKey("DiscriminatorId");
|
||||
|
||||
b.ToTable("DataSchemes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DD.Persistence.Database.Entity.DataSourceSystem", b =>
|
||||
{
|
||||
b.Property<Guid>("SystemId")
|
||||
@ -122,23 +140,6 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
b.ToTable("TimestampedValues");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DD.Persistence.Database.Entity.ValuesIdentity", b =>
|
||||
{
|
||||
b.Property<Guid>("DiscriminatorId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasComment("Дискриминатор системы");
|
||||
|
||||
b.Property<string[]>("Identity")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasComment("Идентификаторы");
|
||||
|
||||
b.HasKey("DiscriminatorId");
|
||||
|
||||
b.ToTable("ValuesIdentities");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DD.Persistence.Database.Model.ChangeLog", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@ -206,8 +207,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
.HasColumnType("uuid")
|
||||
.HasComment("Id автора последнего изменения");
|
||||
|
||||
b.Property<object>("Value")
|
||||
.IsRequired()
|
||||
b.Property<JsonElement>("Value")
|
||||
.HasColumnType("jsonb")
|
||||
.HasComment("Значение уставки");
|
||||
|
||||
@ -229,13 +229,13 @@ namespace DD.Persistence.Database.Postgres.Migrations
|
||||
|
||||
modelBuilder.Entity("DD.Persistence.Database.Entity.TimestampedValues", b =>
|
||||
{
|
||||
b.HasOne("DD.Persistence.Database.Entity.ValuesIdentity", "ValuesIdentity")
|
||||
b.HasOne("DD.Persistence.Database.Entity.DataScheme", "DataScheme")
|
||||
.WithMany()
|
||||
.HasForeignKey("DiscriminatorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("ValuesIdentity");
|
||||
b.Navigation("DataScheme");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace DD.Persistence.Database.Entity;
|
||||
|
||||
public class DataScheme
|
||||
{
|
||||
[Key, Comment("Дискриминатор системы"),]
|
||||
[Key, Comment("Идентификатор схемы данных"),]
|
||||
public Guid DiscriminatorId { get; set; }
|
||||
|
||||
[Comment("Наименования полей в порядке индексации"), Column(TypeName = "jsonb")]
|
||||
|
@ -22,10 +22,10 @@ public class DataSchemeRepository : IDataSchemeRepository
|
||||
await db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public virtual async Task<DataSchemeDto?> GetByDiscriminator(Guid discriminatorId, CancellationToken token)
|
||||
public virtual async Task<DataSchemeDto?> Get(Guid dataSchemeId, CancellationToken token)
|
||||
{
|
||||
var query = GetQueryReadOnly()
|
||||
.Where(e => e.DiscriminatorId == discriminatorId);
|
||||
.Where(e => e.DiscriminatorId == dataSchemeId);
|
||||
var entity = await query.ToArrayAsync();
|
||||
var dto = entity.Select(e => e.Adapt<DataSchemeDto>()).FirstOrDefault();
|
||||
|
||||
|
@ -20,10 +20,10 @@ public class DataSchemeCachedRepository : DataSchemeRepository
|
||||
memoryCache.Set(dataSourceSystemDto.DiscriminatorId, dataSourceSystemDto);
|
||||
}
|
||||
|
||||
public override async Task<DataSchemeDto?> GetByDiscriminator(Guid discriminatorId, CancellationToken token)
|
||||
public override async Task<DataSchemeDto?> Get(Guid discriminatorId, CancellationToken token)
|
||||
{
|
||||
var result = memoryCache.Get<DataSchemeDto>(discriminatorId)
|
||||
?? await base.GetByDiscriminator(discriminatorId, token);
|
||||
?? await base.Get(discriminatorId, token);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ public interface IDataSchemeRepository
|
||||
/// <summary>
|
||||
/// Вычитать схему
|
||||
/// </summary>
|
||||
/// <param name="discriminatorId">Дискриминатор системы</param>
|
||||
/// <param name="dataSchemeId">Идентификатор схемы</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<DataSchemeDto?> GetByDiscriminator(Guid discriminatorId, CancellationToken token);
|
||||
Task<DataSchemeDto?> Get(Guid dataSchemeId, CancellationToken token);
|
||||
}
|
@ -113,14 +113,14 @@ public class TimestampedValuesService : ITimestampedValuesService
|
||||
/// <summary>
|
||||
/// Преобразовать результат запроса в набор dto
|
||||
/// </summary>
|
||||
/// <param name="discriminatorId"></param>
|
||||
/// <param name="dataSchemeId"></param>
|
||||
/// <param name="queryResult"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<IEnumerable<TimestampedValuesDto>> Materialize(Guid discriminatorId, IEnumerable<Tuple<DateTimeOffset, object[]>> queryResult, CancellationToken token)
|
||||
private async Task<IEnumerable<TimestampedValuesDto>> Materialize(Guid dataSchemeId, IEnumerable<Tuple<DateTimeOffset, object[]>> queryResult, CancellationToken token)
|
||||
{
|
||||
var systemSpecification = await dataSchemeRepository.GetByDiscriminator(discriminatorId, token);
|
||||
if (systemSpecification is null)
|
||||
var dataScheme = await dataSchemeRepository.Get(dataSchemeId, token);
|
||||
if (dataScheme is null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
@ -132,7 +132,7 @@ public class TimestampedValuesService : ITimestampedValuesService
|
||||
Timestamp = entity.Item1.ToUniversalTime()
|
||||
};
|
||||
|
||||
var identity = systemSpecification!.PropNames;
|
||||
var identity = dataScheme!.PropNames;
|
||||
var indexedIdentity = identity
|
||||
.Select((value, index) => new { index, value });
|
||||
dto.Values = indexedIdentity
|
||||
@ -154,7 +154,7 @@ public class TimestampedValuesService : ITimestampedValuesService
|
||||
/// <exception cref="InvalidOperationException">Некорректный набор наименований полей</exception>
|
||||
private async Task CreateSystemSpecificationIfNotExist(Guid discriminatorId, string[] fieldNames, CancellationToken token)
|
||||
{
|
||||
var systemSpecification = await dataSchemeRepository.GetByDiscriminator(discriminatorId, token);
|
||||
var systemSpecification = await dataSchemeRepository.Get(discriminatorId, token);
|
||||
if (systemSpecification is null)
|
||||
{
|
||||
systemSpecification = new DataSchemeDto()
|
||||
|
Loading…
Reference in New Issue
Block a user