public void Execute(Dictionary <string, string> input) { if (!input.Any(x => x.Key == PARAMKEYS_CREATE)) { return; } connectionString = DatabaseInstaller.GetSetting(input, DatabaseInstaller.PARAMKEYS_APPDB, string.Empty); Log.Information($"connectionstring censored: {CensorConnectionString(connectionString)}"); masterConnectionString = DatabaseInstaller.GetSetting(input, PARAMKEYS_MASTERDB, string.Empty); Log.Information($"masterconnectionstring censored: {CensorConnectionString(masterConnectionString)}"); newDatabaseName = DatabaseInstaller.GetSetting(input, PARAMKEYS_NEWNAME, string.Empty); Log.Information($"newDatabaseName: {newDatabaseName}"); if (DatabaseServer.TestConnectionString(connectionString)) { throw new Exception("The connection string references an existing database."); } if (string.IsNullOrEmpty(newDatabaseName)) { throw new Exception("A new database name was not specified."); } var builder = new Npgsql.NpgsqlConnectionStringBuilder(connectionString); if (builder.Database.ToLower() != newDatabaseName.ToLower()) { throw new Exception("A new database name does not match the specified connection string."); } CreateDatabase(); }
void IDatabaseAction.Execute(Dictionary <string, string> input) { if (input.Any(x => x.Key == PARAMKEYS_CREATE)) { masterConnectionString = DatabaseInstaller.GetSetting(input, PARAMKEYS_MASTERDB, string.Empty); if (!MasterDbAvailable()) { throw new Exception("Master Db Not Available"); } } else { connectionString = DatabaseInstaller.GetSetting(input, DatabaseInstaller.PARAMKEYS_APPDB, string.Empty); if (!DbAvailable()) { throw new Exception("Database Not Available"); } } }