Добавить партиционирование

This commit is contained in:
Roman Efremov 2024-12-22 21:00:32 +05:00
parent 7fe7357712
commit cdbbcce3bf
41 changed files with 599 additions and 129 deletions

View File

@ -12,7 +12,7 @@ using DD.Persistence.Database.Model;
namespace DD.Persistence.Database.Postgres.Migrations
{
[DbContext(typeof(PersistenceDbContext))]
[DbContext(typeof(PersistencePostgresContext))]
[Migration("20241126071115_Add_ChangeLog")]
partial class Add_ChangeLog
{

View File

@ -1,35 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DD.Persistence.Database.Postgres.Migrations
{
/// <inheritdoc />
public partial class ParameterDataMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ParameterData",
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_ParameterData", x => new { x.DiscriminatorId, x.ParameterId, x.Timestamp });
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ParameterData");
}
}
}

View File

@ -48,30 +48,6 @@ namespace DD.Persistence.Database.Postgres.Migrations.PersistencePostgres
b.ToTable("DrillingSystem");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.ParameterData", b =>
{
b.Property<Guid>("DiscriminatorId")
.HasColumnType("uuid")
.HasComment("Дискриминатор системы");
b.Property<int>("ParameterId")
.HasColumnType("integer")
.HasComment("Id параметра");
b.Property<DateTimeOffset>("Timestamp")
.HasColumnType("timestamp with time zone")
.HasComment("Временная отметка");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("varchar(256)")
.HasComment("Значение параметра в виде строки");
b.HasKey("DiscriminatorId", "ParameterId", "Timestamp");
b.ToTable("ParameterData");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.TechMessage", b =>
{
b.Property<Guid>("EventId")

View File

@ -1,18 +1,18 @@
// <auto-generated />
using System;
using DD.Persistence.Database.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using DD.Persistence.Database.Model;
#nullable disable
namespace DD.Persistence.Database.Postgres.Migrations
namespace DD.Persistence.Database.Postgres.Migrations.PersistencePostgres
{
[DbContext(typeof(PersistenceDbContext))]
[Migration("20241203120141_ParameterDataMigration")]
[DbContext(typeof(PersistencePostgresContext))]
[Migration("20241222112828_ParameterDataMigration")]
partial class ParameterDataMigration
{
/// <inheritdoc />
@ -27,38 +27,43 @@ namespace DD.Persistence.Database.Postgres.Migrations
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack");
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DD.Persistence.Database.Entity.DrillingSystem", b =>
modelBuilder.Entity("DD.Persistence.Database.Entity.DataSourceSystem", b =>
{
b.Property<Guid>("SystemId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasComment("Id системы автобурения");
.HasComment("Id системы - источника данных");
b.Property<string>("Description")
.HasColumnType("text")
.HasComment("Описание системы автобурения");
.HasComment("Описание системы - источника данных");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("varchar(256)")
.HasComment("Наименование системы автобурения");
.HasComment("Наименование системы - источника данных");
b.HasKey("SystemId");
b.ToTable("DrillingSystem");
b.ToTable("DataSourceSystem");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.ParameterData", b =>
{
b.Property<int>("DiscriminatorId")
.HasColumnType("integer")
b.Property<Guid>("DiscriminatorId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasComment("Дискриминатор системы");
b.Property<int>("ParameterId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasComment("Id параметра");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ParameterId"));
b.Property<DateTimeOffset>("Timestamp")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasComment("Временная отметка");
@ -83,27 +88,23 @@ namespace DD.Persistence.Database.Postgres.Migrations
.HasColumnType("integer")
.HasComment("Id Категории важности");
b.Property<double?>("Depth")
.HasColumnType("double precision")
.HasComment("Глубина забоя");
b.Property<int>("EventState")
.HasColumnType("integer")
.HasComment("Статус события");
b.Property<string>("MessageText")
b.Property<Guid>("SystemId")
.HasColumnType("uuid")
.HasComment("Id системы, к которой относится сообщение");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("varchar(512)")
.HasComment("Текст сообщения");
b.Property<Guid>("SystemId")
.HasColumnType("uuid")
.HasComment("Id системы автобурения, к которой относится сообщение");
b.Property<DateTimeOffset>("Timestamp")
.HasColumnType("timestamp with time zone")
.HasComment("Дата возникновения");
b.Property<Guid>("UserId")
.HasColumnType("uuid")
.HasComment("Id пользователя за пультом бурильщика");
b.HasKey("EventId");
b.HasIndex("SystemId");
@ -134,6 +135,59 @@ namespace DD.Persistence.Database.Postgres.Migrations
});
});
modelBuilder.Entity("DD.Persistence.Database.Model.ChangeLog", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasComment("Ключ записи");
b.Property<DateTimeOffset>("Creation")
.HasColumnType("timestamp with time zone")
.HasComment("Дата создания записи");
b.Property<double>("DepthEnd")
.HasColumnType("double precision")
.HasComment("Глубина забоя на дату окончания интервала");
b.Property<double>("DepthStart")
.HasColumnType("double precision")
.HasComment("Глубина забоя на дату начала интервала");
b.Property<Guid>("IdAuthor")
.HasColumnType("uuid")
.HasComment("Автор изменения");
b.Property<Guid>("IdDiscriminator")
.HasColumnType("uuid")
.HasComment("Дискриминатор таблицы");
b.Property<Guid?>("IdEditor")
.HasColumnType("uuid")
.HasComment("Редактор");
b.Property<Guid?>("IdNext")
.HasColumnType("uuid")
.HasComment("Id заменяющей записи");
b.Property<Guid>("IdSection")
.HasColumnType("uuid")
.HasComment("Ключ секции");
b.Property<DateTimeOffset?>("Obsolete")
.HasColumnType("timestamp with time zone")
.HasComment("Дата устаревания (например при удалении)");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("jsonb")
.HasComment("Значение");
b.HasKey("Id");
b.ToTable("ChangeLog");
});
modelBuilder.Entity("DD.Persistence.Database.Model.DataSaub", b =>
{
b.Property<DateTimeOffset>("Date")
@ -243,7 +297,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
modelBuilder.Entity("DD.Persistence.Database.Entity.TechMessage", b =>
{
b.HasOne("DD.Persistence.Database.Entity.DrillingSystem", "System")
b.HasOne("DD.Persistence.Database.Entity.DataSourceSystem", "System")
.WithMany()
.HasForeignKey("SystemId")
.OnDelete(DeleteBehavior.Cascade)

View File

@ -0,0 +1,61 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DD.Persistence.Database.Postgres.Migrations.PersistencePostgres
{
/// <inheritdoc />
public partial class ParameterDataMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ParameterData",
columns: table => new
{
DiscriminatorId = table.Column<Guid>(type: "uuid", nullable: false, comment: "Дискриминатор системы"),
ParameterId = table.Column<int>(type: "integer", nullable: false, comment: "Id параметра")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Временная отметка"),
Value = table.Column<string>(type: "varchar(256)", nullable: true, comment: "Значение параметра в виде строки")
},
constraints: table =>
{
table.PrimaryKey("PK_ParameterData", x => new { x.DiscriminatorId, x.ParameterId, x.Timestamp });
});
string sql;
for (int i = 1; i <= 25; i++)
{
sql = $"create table if not exists \"ParameterData{i}\" (like public.\"ParameterData\" including all) inherits (public.\"ParameterData\");";
migrationBuilder.Sql(sql);
}
//sql = "create or replace function partition_for_parameter_data() returns trigger as $$ " +
// "DECLARE " +
// " v_parition_name text; " +
// "BEGIN " +
// " v_parition_name := format( 'ParameterData%s', NEW.\"ParameterId\" / 1000 ); " +
// " execute 'INSERT INTO public.\"' || v_parition_name || '\" VALUES ( ($1).* )' USING NEW; " +
// " return NULL; " +
// "END; " +
// "$$ language plpgsql;";
//migrationBuilder.Sql(sql);
//sql = "create or replace trigger partition_parameter_data " +
// "before insert on public.\"ParameterData\" " +
// "for each row execute procedure public.partition_for_parameter_data();";
//migrationBuilder.Sql(sql);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ParameterData");
}
}
}

View File

@ -1,10 +1,10 @@
// <auto-generated />
using System;
using DD.Persistence.Database.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using DD.Persistence.Database.Model;
#nullable disable
@ -48,19 +48,23 @@ namespace DD.Persistence.Database.Postgres.Migrations
modelBuilder.Entity("DD.Persistence.Database.Entity.ParameterData", b =>
{
b.Property<Guid>("DiscriminatorId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasComment("Дискриминатор системы");
b.Property<int>("ParameterId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasComment("Id параметра");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ParameterId"));
b.Property<DateTimeOffset>("Timestamp")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasComment("Временная отметка");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("varchar(256)")
.HasComment("Значение параметра в виде строки");
@ -69,6 +73,7 @@ namespace DD.Persistence.Database.Postgres.Migrations
b.ToTable("ParameterData");
});
modelBuilder.Entity("DD.Persistence.Database.Entity.TechMessage", b =>
{
b.Property<Guid>("EventId")

View File

@ -2,8 +2,9 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData")]
[PrimaryKey(nameof(DiscriminatorId), nameof(ParameterId), nameof(Timestamp))]
public class ParameterData
{
@ -14,7 +15,7 @@ public class ParameterData
public int ParameterId { get; set; }
[Column(TypeName = "varchar(256)"), Comment("Значение параметра в виде строки")]
public required string Value { get; set; }
public string Value { get; set; }
[Comment("Временная отметка")]
public DateTimeOffset Timestamp { get; set; }

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData1")]
public class ParameterData1 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData10")]
public class ParameterData10 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData11")]
public class ParameterData11 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData12")]
public class ParameterData12 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData13")]
public class ParameterData13 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData14")]
public class ParameterData14 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData15")]
public class ParameterData15 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData16")]
public class ParameterData16 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData17")]
public class ParameterData17 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData18")]
public class ParameterData18 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData19")]
public class ParameterData19 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData2")]
public class ParameterData2 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData20")]
public class ParameterData20 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData21")]
public class ParameterData21 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData22")]
public class ParameterData22 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData23")]
public class ParameterData23 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData24")]
public class ParameterData24 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData25")]
public class ParameterData25 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData3")]
public class ParameterData3 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData4")]
public class ParameterData4 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData5")]
public class ParameterData5 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData6")]
public class ParameterData6 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData7")]
public class ParameterData7 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData8")]
public class ParameterData8 : ParameterData
{
}

View File

@ -0,0 +1,10 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DD.Persistence.Database.Entity.ParameterData;
[Table("ParameterData9")]
public class ParameterData9 : ParameterData
{
}

View File

@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using DD.Persistence.Database.Entity;
using DD.Persistence.Database.Model;
using DD.Persistence.Database.Entity.ParameterData;
namespace DD.Persistence.Database;
@ -20,8 +21,34 @@ public class PersistenceDbContext : DbContext
public DbSet<TechMessage> TechMessage => Set<TechMessage>();
public DbSet<ParameterData> ParameterData => Set<ParameterData>();
public DbSet<ParameterData1> ParameterData1 => Set<ParameterData1>();
public DbSet<ParameterData2> ParameterData2 => Set<ParameterData2>();
public DbSet<ParameterData3> ParameterData3 => Set<ParameterData3>();
public DbSet<ParameterData4> ParameterData4 => Set<ParameterData4>();
public DbSet<ParameterData5> ParameterData5 => Set<ParameterData5>();
public DbSet<ParameterData6> ParameterData6 => Set<ParameterData6>();
public DbSet<ParameterData7> ParameterData7 => Set<ParameterData7>();
public DbSet<ParameterData8> ParameterData8 => Set<ParameterData8>();
public DbSet<ParameterData9> ParameterData9 => Set<ParameterData9>();
public DbSet<ParameterData10> ParameterData10 => Set<ParameterData10>();
public DbSet<ParameterData11> ParameterData11 => Set<ParameterData11>();
public DbSet<ParameterData12> ParameterData12 => Set<ParameterData12>();
public DbSet<ParameterData13> ParameterData13 => Set<ParameterData13>();
public DbSet<ParameterData14> ParameterData14 => Set<ParameterData14>();
public DbSet<ParameterData15> ParameterData15 => Set<ParameterData15>();
public DbSet<ParameterData16> ParameterData16 => Set<ParameterData16>();
public DbSet<ParameterData17> ParameterData17 => Set<ParameterData17>();
public DbSet<ParameterData18> ParameterData18 => Set<ParameterData18>();
public DbSet<ParameterData19> ParameterData19 => Set<ParameterData19>();
public DbSet<ParameterData20> ParameterData20 => Set<ParameterData20>();
public DbSet<ParameterData21> ParameterData21 => Set<ParameterData21>();
public DbSet<ParameterData22> ParameterData22 => Set<ParameterData22>();
public DbSet<ParameterData23> ParameterData23 => Set<ParameterData23>();
public DbSet<ParameterData24> ParameterData24 => Set<ParameterData24>();
public DbSet<ParameterData25> ParameterData25 => Set<ParameterData25>();
public DbSet<DataSourceSystem> DataSourceSystem => Set<DataSourceSystem>();
public DbSet<DataSourceSystem> DataSourceSystem => Set<DataSourceSystem>();
public PersistenceDbContext(DbContextOptions options)
: base(options)

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DD.Persistence.Database.UsefulQueries
{
class partition_function
{
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DD.Persistence.Database.UsefulQueries
{
class partition_function
{
}
}

View File

@ -1,10 +1,10 @@
using Microsoft.Extensions.DependencyInjection;
using DD.Persistence.Database.Entity;
using DD.Persistence.Models;
using System.Net;
using Xunit;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client;
using DD.Persistence.Database.Entity.ParameterData;
namespace DD.Persistence.IntegrationTests.Controllers;
public class WitsDataControllerTest : BaseIntegrationTest

View File

@ -1,8 +1,8 @@
using Mapster;
using Microsoft.EntityFrameworkCore;
using DD.Persistence.Database.Entity;
using DD.Persistence.Models;
using DD.Persistence.Repositories;
using DD.Persistence.Database.Entity.ParameterData;
namespace DD.Persistence.Repository.Repositories;
public class ParameterRepository : IParameterRepository
@ -83,4 +83,105 @@ public class ParameterRepository : IParameterRepository
return result;
}
//public async Task<int> AddRange(IEnumerable<ParameterDto> dtos, CancellationToken token)
//{
// int result = 0;
// var groups = dtos.GroupBy(e => e.ParameterId / 1000);
// foreach (var group in groups)
// {
// switch (group.Key)
// {
// case 1:
// result += await AddRange<ParameterData1>(dtos, token);
// break;
// case 2:
// result += await AddRange<ParameterData2>(dtos, token);
// break;
// case 3:
// result += await AddRange<ParameterData3>(dtos, token);
// break;
// case 4:
// result += await AddRange<ParameterData4>(dtos, token);
// break;
// case 5:
// result += await AddRange<ParameterData5>(dtos, token);
// break;
// case 6:
// result += await AddRange<ParameterData6>(dtos, token);
// break;
// case 7:
// result += await AddRange<ParameterData7>(dtos, token);
// break;
// case 8:
// result += await AddRange<ParameterData8>(dtos, token);
// break;
// case 9:
// result += await AddRange<ParameterData9>(dtos, token);
// break;
// case 10:
// result += await AddRange<ParameterData10>(dtos, token);
// break;
// case 11:
// result += await AddRange<ParameterData11>(dtos, token);
// break;
// case 12:
// result += await AddRange<ParameterData12>(dtos, token);
// break;
// case 13:
// result += await AddRange<ParameterData13>(dtos, token);
// break;
// case 14:
// result += await AddRange<ParameterData14>(dtos, token);
// break;
// case 15:
// result += await AddRange<ParameterData15>(dtos, token);
// break;
// case 16:
// result += await AddRange<ParameterData16>(dtos, token);
// break;
// case 17:
// result += await AddRange<ParameterData17>(dtos, token);
// break;
// case 18:
// result += await AddRange<ParameterData18>(dtos, token);
// break;
// case 19:
// result += await AddRange<ParameterData19>(dtos, token);
// break;
// case 20:
// result += await AddRange<ParameterData20>(dtos, token);
// break;
// case 21:
// result += await AddRange<ParameterData21>(dtos, token);
// break;
// case 22:
// result += await AddRange<ParameterData22>(dtos, token);
// break;
// case 23:
// result += await AddRange<ParameterData23>(dtos, token);
// break;
// case 24:
// result += await AddRange<ParameterData24>(dtos, token);
// break;
// case 25:
// result += await AddRange<ParameterData25>(dtos, token);
// break;
// }
// }
// return result;
//}
//private async Task<int> AddRange<T>(IEnumerable<ParameterDto> dtos, CancellationToken token)
// where T : ParameterData
//{
// var t = dtos.Where(e => e.Value == null);
// var entities = dtos.Select(e => e.Adapt<T>());
// var tt = entities.Where(e => e.Value == null);
// await db.Set<T>().AddRangeAsync(entities, token);
// var result = await db.SaveChangesAsync(token);
// return result;
//}
}

View File

@ -10,5 +10,5 @@ public class DbConnection
public string Password { get; set; } = null!;
public string GetConnectionString() =>
$"Host={Host};Database={Guid.NewGuid()};Port={Port};Username={Username};Password={Password};Persist Security Info=True;Include Error Detail=True";
$"Host={Host};Database=persistence;Port={Port};Username={Username};Password={Password};Persist Security Info=True;Include Error Detail=True";
}

View File

@ -26,50 +26,54 @@ public static class WitsDataBenchmark
var sw = new Stopwatch();
// Create a new bitmap plot surface
var plotSurface = new NPlot.Bitmap.PlotSurface2D(800, 600);
//// Create a new bitmap plot surface
//var plotSurface = new NPlot.Bitmap.PlotSurface2D(800, 600);
// Create a line plot
var linePlot = new LinePlot();
var abscissaData = new List<double>() {};
var ordinateData = new List<double>() {};
//// Create a line plot
//var linePlot = new LinePlot();
var saved = 0;
foreach (var item in data) {
var time = sw.Elapsed;
sw.Start();
var response = await client.AddRange(item, source.Token);
sw.Stop();
//var abscissaData = new List<double>() { };
//var ordinateData = new List<double>() { };
Console.WriteLine($"Сохранено: {response.ToString()}");
saved = saved + response;
abscissaData.Add(saved/100_000);
//var saved = 0;
//foreach (var item in data)
//{
// var time = sw.Elapsed;
Console.WriteLine($"Затрачено времени на сохранение части: {sw.Elapsed - time}");
ordinateData.Add((double)(sw.Elapsed - time).TotalSeconds);
}
// sw.Start();
// var response = await client.AddRange(item, source.Token);
// sw.Stop();
Console.WriteLine($"Затрачено времени на сохранение: {sw.Elapsed}");
// Console.WriteLine($"Сохранено: {response.ToString()}");
// saved = saved + response;
// abscissaData.Add(saved / 100_000);
// Add the line plot to the plot surface
linePlot.AbscissaData = abscissaData;
linePlot.OrdinateData = ordinateData;
plotSurface.Add(linePlot);
// Console.WriteLine($"Затрачено времени на сохранение части: {sw.Elapsed - time}");
// ordinateData.Add((double)(sw.Elapsed - time).TotalSeconds);
//}
// Customize the plot (e.g., titles, labels)
plotSurface.Title = "График";
plotSurface.XAxis1.Label = "Количество сохраненных записей в БД (100.000)";
plotSurface.YAxis1.Label = "Время на сохранение 100.000 записей (сек.)";
//Console.WriteLine($"Затрачено времени на сохранение: {sw.Elapsed}");
// Refresh the plot to render it
plotSurface.Refresh();
#pragma warning disable
// Save the plot as a PNG image
plotSurface.Bitmap.Save("C:\\Users\\fremo\\source\\repos\\persistence\\Persistence.Benchmark\\plot.png", System.Drawing.Imaging.ImageFormat.Png);
#pragma warning enable
//// Add the line plot to the plot surface
//linePlot.AbscissaData = abscissaData;
//linePlot.OrdinateData = ordinateData;
//plotSurface.Add(linePlot);
//// Customize the plot (e.g., titles, labels)
//plotSurface.Title = "График";
//plotSurface.XAxis1.Label = "Количество сохраненных записей в БД (100.000)";
//plotSurface.YAxis1.Label = "Время на сохранение 100.000 записей (сек.)";
//// Refresh the plot to render it
//plotSurface.Refresh();
//#pragma warning disable
//// Save the plot as a PNG image
//plotSurface.Bitmap.Save("C:\\Users\\fremo\\source\\repos\\persistence\\Persistence.Benchmark\\plot.png", System.Drawing.Imaging.ImageFormat.Png);
//#pragma warning enable
var dis = Guid.Parse(discriminatorId);
var date = DateTime.Now.AddDays(-1);
@ -80,6 +84,7 @@ public static class WitsDataBenchmark
sw.Stop();
Console.WriteLine($"Затрачено времени на вычитку: {sw.Elapsed}");
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
@ -90,13 +95,13 @@ public static class WitsDataBenchmark
{
var result = new List<List<WitsDataDto>>();
int enumerableCount = countToCreate / 100_000 + (countToCreate % 100_000 == 0 ? 0 : 1);
int enumerableCount = countToCreate / 25_000 + (countToCreate % 25_000 == 0 ? 0 : 1);
for (var k = 0; k < enumerableCount; k++)
{
var dtos = new List<WitsDataDto>();
for (var j = 0; j < 1000; j++)
{
for (var i = 0; i < 100; i++)
for (var i = 0; i < 25; i++)
{
var timestamped = DateTimeOffset.UtcNow;
var random = new Random();

View File

@ -50,7 +50,7 @@ public class WebAppFactoryFixture : WebApplicationFactory<DD.Persistence.App.Pro
var scopedServices = scope.ServiceProvider;
var dbContext = scopedServices.GetRequiredService<PersistencePostgresContext>();
dbContext.Database.EnsureCreatedAndMigrated();
//dbContext.Database.EnsureCreatedAndMigrated();
dbContext.SaveChanges();
});
}