From 344428743c365a3708b07c97e8ba5185a5e6e9af Mon Sep 17 00:00:00 2001 From: Niklas Hamann Date: Tue, 14 Oct 2025 14:50:00 +0200 Subject: [PATCH] Fix ConnectionString forwarded improperly Problem: Using a user other than `postgres` causes the connection test to fail. This occurs because the ConnectionString lacks a `Database` attribute during the test. As a result, the npgsql defaults to using the `User` attribute as the database name, which leads to a `DatabaseNotFound` error as no matching database exists. Solution: Using a custom config for testing the database server's connection status with database being "postgres". INFO: This migh lead to an edge-case where the user in unable to create/ delete databases if the "postgres" database has been deleted. Also added missing `outline` to the save button for the database config. closes #539 --- .../src/databases/container/DatabaseModel.tsx | 2 +- .../NpgsqlModelConfigurator.cs | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Moryx.CommandCenter.Web/src/databases/container/DatabaseModel.tsx b/src/Moryx.CommandCenter.Web/src/databases/container/DatabaseModel.tsx index 2747a0ce4..bd041d747 100644 --- a/src/Moryx.CommandCenter.Web/src/databases/container/DatabaseModel.tsx +++ b/src/Moryx.CommandCenter.Web/src/databases/container/DatabaseModel.tsx @@ -377,7 +377,7 @@ class DatabaseModel extends React.Component - + diff --git a/src/Moryx.Model.PostgreSQL/NpgsqlModelConfigurator.cs b/src/Moryx.Model.PostgreSQL/NpgsqlModelConfigurator.cs index 16ec5c904..355d610da 100644 --- a/src/Moryx.Model.PostgreSQL/NpgsqlModelConfigurator.cs +++ b/src/Moryx.Model.PostgreSQL/NpgsqlModelConfigurator.cs @@ -6,6 +6,7 @@ using System.Data.Common; using System.Diagnostics; using System.IO; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; @@ -94,6 +95,41 @@ private static NpgsqlConnectionStringBuilder CreateConnectionStringBuilder(IData return builder; } + /// + /// Replaces given config's database with "postgres". + /// This config can be used to check availability of + /// the database server. + /// + /// + /// Modified copy of given config + private static IDatabaseConfig CreateTestDatabaseConfig(IDatabaseConfig config) + { + var testConfig = new DatabaseConfig + { + ConfiguratorTypename = config.ConfiguratorTypename, + ConnectionSettings = config.ConnectionSettings, + ConfigState = config.ConfigState, + LoadError = config.LoadError + }; + + var builder = new NpgsqlConnectionStringBuilder(testConfig.ConnectionSettings.ConnectionString) + { + Database = "postgres" + }; + + testConfig.ConnectionSettings.ConnectionString = builder.ConnectionString; + + return testConfig; + } + + /// + public override Task TestConnection(IDatabaseConfig config) + { + // Using the "postgres" database to check the server's availability. + // might lead to edge-case when "postgres" database has been deleted. + return base.TestConnection(CreateTestDatabaseConfig(config)); + } + /// public override Task RestoreDatabase(IDatabaseConfig config, string filePath) {