Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class DatabaseModel extends React.Component<DatabaseModelPropsModel & DatabaseMo
</Stack>
</GridLegacy>
<GridLegacy item={true} md={12}>
<Button color="primary" onClick={() => this.onSave()}>Save</Button>
<Button color="primary" variant="outlined" onClick={() => this.onSave()}>Save</Button>
</GridLegacy>
</DatabaseSection>
<DatabaseSection title="Backup &amp; Restore">
Expand Down
36 changes: 36 additions & 0 deletions src/Moryx.Model.PostgreSQL/NpgsqlModelConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,6 +95,41 @@ private static NpgsqlConnectionStringBuilder CreateConnectionStringBuilder(IData
return builder;
}

/// <summary>
/// Replaces given config's database with "postgres".
/// This config can be used to check availability of
/// the database server.
/// </summary>
/// <param name="config"></param>
/// <returns>Modified copy of given config</returns>
private static IDatabaseConfig CreateTestDatabaseConfig(IDatabaseConfig config)
{
var testConfig = new DatabaseConfig<DatabaseConnectionSettings>
{
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;
}

/// <inheritdoc/>
public override Task<TestConnectionResult> 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));
}

/// <inheritdoc />
public override Task RestoreDatabase(IDatabaseConfig config, string filePath)
{
Expand Down
Loading