Skip to content

Commit a544ae5

Browse files
au-eedroyad
andauthored
Make it possible to change the master database name (#21)
* put master db name into a property to be able to change it from the outside * Describe MasterDatabaseName property * Used `PostgresqlConnectionOptions` to pass MasterDatabaseName instead of a static --------- Co-authored-by: Robert Wagner <[email protected]>
1 parent 1b2b5b4 commit a544ae5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/dbup-postgresql/PostgresqlConnectionOptions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ public class PostgresqlConnectionOptions
1414
public X509Certificate2 ClientCertificate { get; set; }
1515

1616
/// <summary>
17-
// Custom handler to verify the remote SSL certificate.
18-
// Ignored if Npgsql.NpgsqlConnectionStringBuilder.TrustServerCertificate is set.
17+
/// Custom handler to verify the remote SSL certificate.
18+
/// Ignored if Npgsql.NpgsqlConnectionStringBuilder.TrustServerCertificate is set.
1919
/// </summary>
2020
public RemoteCertificateValidationCallback UserCertificateValidationCallback { get; set; }
21+
22+
/// <summary>
23+
/// The database to connect to initially. Default is 'postgres'.
24+
/// </summary>
25+
public string MasterDatabaseName { get; set; } = "postgres";
2126
}
2227
}

src/dbup-postgresql/PostgresqlExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ private static void PostgresqlDatabase(this SupportedDatabasesForEnsureDatabase
159159
PostgresqlDatabase(supported, connectionString, logger, options);
160160
}
161161

162-
private static void PostgresqlDatabase(this SupportedDatabasesForEnsureDatabase supported, string connectionString, IUpgradeLog logger, PostgresqlConnectionOptions connectionOptions)
162+
private static void PostgresqlDatabase(
163+
this SupportedDatabasesForEnsureDatabase supported,
164+
string connectionString,
165+
IUpgradeLog logger,
166+
PostgresqlConnectionOptions connectionOptions
167+
)
163168
{
164169
if (supported == null) throw new ArgumentNullException("supported");
165170

@@ -179,7 +184,7 @@ private static void PostgresqlDatabase(this SupportedDatabasesForEnsureDatabase
179184
throw new InvalidOperationException("The connection string does not specify a database name.");
180185
}
181186

182-
masterConnectionStringBuilder.Database = "postgres";
187+
masterConnectionStringBuilder.Database = connectionOptions.MasterDatabaseName;
183188

184189
var logMasterConnectionStringBuilder = new NpgsqlConnectionStringBuilder(masterConnectionStringBuilder.ConnectionString);
185190
if (!string.IsNullOrEmpty(logMasterConnectionStringBuilder.Password))

0 commit comments

Comments
 (0)