Skip to content

Commit

Permalink
fix database access
Browse files Browse the repository at this point in the history
  • Loading branch information
NastasiyaT committed Oct 13, 2023
1 parent 5d054c7 commit 6c58562
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ dependencies {
implementation("org.postgresql:postgresql:42.6.0")

testImplementation("org.assertj:assertj-core:3.24.2")
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation(platform("org.junit:junit-bom:5.9.2"))
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
}

tasks.test {
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/hexlet/code/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class App {

private static String getDatabaseUrl() {
return System.getenv()
.getOrDefault("APP_ENV", "jdbc:h2:mem:webapp;DB_CLOSE_DELAY=-1;");
.getOrDefault("JDBC_ENV", "jdbc:h2:mem:webapp;DB_CLOSE_DELAY=-1;");
}

private static InputStream getFileFromResourceAsStream(String fileName) {
Expand Down Expand Up @@ -53,7 +53,11 @@ private static int getPort() {
public static Javalin getApp() throws IOException, SQLException {

var hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(getDatabaseUrl());
String databaseUrl = getDatabaseUrl();
if (databaseUrl.contains("postgresql")) {
hikariConfig.setDriverClassName(org.postgresql.Driver.class.getName());
}
hikariConfig.setJdbcUrl(databaseUrl);

var dataSource = new HikariDataSource(hikariConfig);
String sql = getContentFromStream(getFileFromResourceAsStream("schema.sql"));
Expand Down

0 comments on commit 6c58562

Please sign in to comment.