From c2de8a0cc27a24e066b1cccf50710feefa3d5355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D1=8F=20=D0=91=D0=B8=D0=B7=D1=8E=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0?= Date: Tue, 28 Jan 2025 12:30:58 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8:=20=D1=83=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=D1=80=D0=B8=D0=B5=D0=B2,=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=B8=20=D1=82?= =?UTF-8?q?.=D0=B4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DD.Persistence.App/appsettings.json | 2 +- .../{UnitTest1.cs => UnitTestCheckHyperTables.cs} | 6 +++--- .../Extensions/EFExtensionsPartitioning.cs | 12 +++--------- 3 files changed, 7 insertions(+), 13 deletions(-) rename DD.Persistence.Database.Postgres.Test/{UnitTest1.cs => UnitTestCheckHyperTables.cs} (91%) diff --git a/DD.Persistence.App/appsettings.json b/DD.Persistence.App/appsettings.json index 9b0d5be..7ad8c67 100644 --- a/DD.Persistence.App/appsettings.json +++ b/DD.Persistence.App/appsettings.json @@ -6,7 +6,7 @@ } }, "ConnectionStrings": { - "DefaultConnection": "Host=localhost:5462;Database=persistence;Username=postgres;Password=postgres;Persist Security Info=True" + "DefaultConnection": "Host=localhost;Database=persistence;Username=postgres;Password=postgres;Persist Security Info=True" }, "AllowedHosts": "*", "NeedUseKeyCloak": false, diff --git a/DD.Persistence.Database.Postgres.Test/UnitTest1.cs b/DD.Persistence.Database.Postgres.Test/UnitTestCheckHyperTables.cs similarity index 91% rename from DD.Persistence.Database.Postgres.Test/UnitTest1.cs rename to DD.Persistence.Database.Postgres.Test/UnitTestCheckHyperTables.cs index a7fe654..9c96454 100644 --- a/DD.Persistence.Database.Postgres.Test/UnitTest1.cs +++ b/DD.Persistence.Database.Postgres.Test/UnitTestCheckHyperTables.cs @@ -5,19 +5,19 @@ using Npgsql; namespace DD.Persistence.Database.Postgres.Test; -public class UnitTest1 : IClassFixture +public class UnitTestCheckHyperTables : IClassFixture { private ServiceProvider _serviceProvider; private string _connectionString; - public UnitTest1(DbFixture fixture) + public UnitTestCheckHyperTables(DbFixture fixture) { _serviceProvider = fixture.serviceProvider; _connectionString = fixture.connectionString; } [Fact] - public void CreateHyperTable() + public void CreateHyperTable_For_ParameterData_Return_Success() { var entity = new ParameterData() { diff --git a/DD.Persistence.Database.Postgres/Extensions/EFExtensionsPartitioning.cs b/DD.Persistence.Database.Postgres/Extensions/EFExtensionsPartitioning.cs index 9fb78ee..374fa6e 100644 --- a/DD.Persistence.Database.Postgres/Extensions/EFExtensionsPartitioning.cs +++ b/DD.Persistence.Database.Postgres/Extensions/EFExtensionsPartitioning.cs @@ -25,6 +25,7 @@ public static class EFExtensionsPartitioning /// private static void AddParameterDataPartitioning(this DatabaseFacade db) { + var dayCount = 1; var type = typeof(ParameterData); var tableAttribute = type.GetCustomAttribute(); if (tableAttribute is null) @@ -33,17 +34,10 @@ public static class EFExtensionsPartitioning } var sqlCreateHypertableString = $"SELECT create_hypertable('{tableAttribute.Name}'," + - $"by_range('{nameof(ParameterData.Timestamp)}', INTERVAL '1 day'), if_not_exists => {true});"; + $"by_range('{nameof(ParameterData.Timestamp)}', INTERVAL '{dayCount} 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); + $"by_hash('{nameof(ParameterData.ParameterId)}', {dayCount}));"; } }