fix/partitioning-small-fix #21
@ -6,7 +6,7 @@
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=localhost;Database=persistence;Username=postgres;Password=postgres;Persist Security Info=True"
|
||||
"DefaultConnection": "Host=localhost:5462;Database=persistence;Username=postgres;Password=postgres;Persist Security Info=True"
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"NeedUseKeyCloak": false,
|
||||
|
@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DD.Persistence.Database.Postgres\DD.Persistence.Database.Postgres.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
85
DD.Persistence.Database.Postgres.Test/UnitTest1.cs
Normal file
85
DD.Persistence.Database.Postgres.Test/UnitTest1.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using DD.Persistence.Database.Entity;
|
||||
using DD.Persistence.Database.Model;
|
||||
using DD.Persistence.Database.Postgres.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace DD.Persistence.Database.Postgres.Test;
|
||||
|
||||
public class UnitTest1
|
||||
{
|
||||
private string connectionString;
|
||||
private IHost host;
|
||||
|
||||
public UnitTest1()
|
||||
{
|
||||
connectionString = "Host=localhost;Port=5462;Username=postgres;Password=postgres;Database=persistence5";
|
||||
|
||||
|
||||
|
||||
var builder = Host.CreateApplicationBuilder();
|
||||
builder.Services.AddDbContext<PersistencePostgresContext>(options =>
|
||||
options.UseNpgsql(connectionString));
|
||||
|
||||
builder.Services.AddScoped<DbContext>(provider => provider.GetRequiredService<PersistencePostgresContext>());
|
||||
|
||||
host = builder.Build();
|
||||
using var scope = host.Services.CreateScope();
|
||||
var provider = scope.ServiceProvider;
|
||||
|
||||
var context = provider.GetRequiredService<PersistencePostgresContext>();
|
||||
context.Database.EnsureCreatedAndMigrated();
|
||||
context.Database.AddPartitioning();
|
||||
context.SaveChanges();
|
||||
|
||||
|
||||
//using var scope2 = builder..CreateScope();
|
||||
//var scopedServices = scope.ServiceProvider;
|
||||
|
||||
//var dbContext = scopedServices.GetRequiredService<PersistencePostgresContext>();
|
||||
//dbContext.Database.EnsureCreatedAndMigrated();
|
||||
//dbContext.SaveChanges();
|
||||
}
|
||||
[Fact]
|
||||
public void CreateHyperTable()
|
||||
{
|
||||
var entity = new ParameterData() {
|
||||
DiscriminatorId = Guid.NewGuid(),
|
||||
ParameterId = 1,
|
||||
Timestamp = DateTime.UtcNow,
|
||||
Value = "123"
|
||||
};
|
||||
|
||||
var scope = host.Services.CreateScope();
|
||||
|
||||
var context = scope.ServiceProvider.GetRequiredService<PersistencePostgresContext>();
|
||||
|
||||
context.ParameterData.Add(entity);
|
||||
context.SaveChanges();
|
||||
|
||||
entity.Timestamp = DateTime.UtcNow.AddDays(1);
|
||||
context.ParameterData.Add(entity);
|
||||
context.SaveChanges();
|
||||
|
||||
entity.Timestamp = DateTime.UtcNow.AddDays(2);
|
||||
context.ParameterData.Add(entity);
|
||||
context.SaveChanges();
|
||||
|
||||
entity.Timestamp = DateTime.UtcNow.AddDays(3);
|
||||
context.ParameterData.Add(entity);
|
||||
context.SaveChanges();
|
||||
|
||||
entity.Timestamp = DateTime.UtcNow.AddDays(4);
|
||||
context.ParameterData.Add(entity);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
//public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
// Host.CreateDefaultBuilder(args)
|
||||
// .ConfigureWebHostDefaults(webBuilder =>
|
||||
// {
|
||||
// webBuilder.UseStartup<Startup>();
|
||||
// });
|
||||
}
|
@ -32,13 +32,18 @@ public static class EFExtensionsPartitioning
|
||||
return;
|
||||
}
|
||||
|
||||
const int sectionsNumber = 2;
|
||||
const int chunkTimeInterval = 5;
|
||||
var sqlString = $"SELECT create_hypertable('{tableAttribute.Name}'," +
|
||||
$"'{nameof(ParameterData.Timestamp)}'," +
|
||||
$"'{nameof(ParameterData.ParameterId)}'," +
|
||||
$"{sectionsNumber}," +
|
||||
$"chunk_time_interval => INTERVAL '{chunkTimeInterval} day');";
|
||||
db.ExecuteSqlRaw(sqlString);
|
||||
var sqlCreateHypertableString = $"SELECT create_hypertable('{tableAttribute.Name}'," +
|
||||
$"by_range('{nameof(ParameterData.Timestamp)}', INTERVAL '1 day'), if_not_exists => {true});";
|
||||
db.ExecuteSqlRaw(sqlCreateHypertableString);
|
||||
|
||||
var sqlCreateDimensionString = $"SELECT add_dimension('{tableAttribute.Name}'," +
|
||||
$"by_hash('{nameof(ParameterData.ParameterId)}', 1));";
|
||||
db.ExecuteSqlRaw(sqlCreateDimensionString);
|
||||
//var sqlString = $"SELECT create_hypertable('{tableAttribute.Name}'," +
|
||||
// $"'{nameof(ParameterData.Timestamp)}'," +
|
||||
// $"'{nameof(ParameterData.ParameterId)}'," +
|
||||
// $"{sectionsNumber}," +
|
||||
// $"chunk_time_interval => INTERVAL '{chunkTimeInterval} day');";
|
||||
//db.ExecuteSqlRaw(sqlString);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решен
|
||||
.gitea\workflows\integrationTests.yaml = .gitea\workflows\integrationTests.yaml
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DD.Persistence.Database.Postgres.Test", "DD.Persistence.Database.Postgres.Test\DD.Persistence.Database.Postgres.Test.csproj", "{47142566-9EAB-4FB5-92EC-9DCB02CAC890}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -85,6 +87,10 @@ Global
|
||||
{B8C774E6-6B75-41AC-B3CF-10BD3623B2FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B8C774E6-6B75-41AC-B3CF-10BD3623B2FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B8C774E6-6B75-41AC-B3CF-10BD3623B2FA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{47142566-9EAB-4FB5-92EC-9DCB02CAC890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{47142566-9EAB-4FB5-92EC-9DCB02CAC890}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{47142566-9EAB-4FB5-92EC-9DCB02CAC890}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{47142566-9EAB-4FB5-92EC-9DCB02CAC890}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user