Skip to content

Commit

Permalink
fix: hook postgres host config up
Browse files Browse the repository at this point in the history
  • Loading branch information
sotterbeck committed Aug 12, 2024
1 parent c606c8a commit bafc93b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class PersistenceModule extends AbstractModule {
@Provides
@Singleton
static DataSource provideDataSource(FileConfiguration config) {
return new HikariDataSourceProvider.Builder(
config.getString("postgres.database"),
config.getString("postgres.username"),
config.getString("postgres.password"))
String database = config.getString("postgres.database");
String username = config.getString("postgres.username");
String password = config.getString("postgres.password");
return new HikariDataSourceProvider.Builder(database, username, password)
.host(config.getString("postgres.host"))
.port(config.getInt("postgres.port"))
.schema(config.getString("postgres.schema"))
.build()
.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ public class HikariDataSourceProvider implements Supplier<DataSource> {
private final String password;
private final String dataSourceClassName;
private final String schema;
private final String host;
private final int port;

private HikariDataSourceProvider(Builder builder) {
databaseName = builder.databaseName;
user = builder.user;
password = builder.password;
host = builder.host;
port = builder.port;
dataSourceClassName = builder.dataSourceClassName;
schema = builder.schema;
}
Expand All @@ -35,6 +39,8 @@ private Properties getDatabaseProperties() {
properties.setProperty("dataSource.user", user);
properties.setProperty("dataSource.password", password);
properties.setProperty("dataSource.databaseName", databaseName);
properties.setProperty("dataSource.serverName", host);
properties.setProperty("dataSource.portNumber", String.valueOf(port));
properties.setProperty("dataSource.currentSchema", schema);
return properties;
}
Expand All @@ -44,6 +50,8 @@ public static class Builder {
private final String databaseName;
private final String user;
private final String password;
private String host = "localhost";
private int port = 5432;
private String dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource";
private String schema;

Expand All @@ -63,6 +71,16 @@ public Builder schema(String schema) {
return this;
}

public Builder host(String host) {
this.host = host;
return this;
}

public Builder port(int port) {
this.port = port;
return this;
}

public Supplier<DataSource> build() {
return new HikariDataSourceProvider(this);
}
Expand Down
3 changes: 2 additions & 1 deletion entrypoints/papermc/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
postgres:
host: "127.0.0.1:5432"
host: "127.0.0.1"
port: 5432
database: postgres
username: postgres
password: password
Expand Down

0 comments on commit bafc93b

Please sign in to comment.