libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit db76884dee5897197ef0f3a0d8f72c58ea7e7723
parent ff3afba707bbd3fb0bdbafacaa8bad77f55719fb
Author: Florian Dold <florian@dold.me>
Date:   Mon, 16 Oct 2023 12:14:15 +0200

normalize postgres:// URI to postgresql:// for JDBC

Diffstat:
Mutil/src/main/kotlin/DB.kt | 9++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/util/src/main/kotlin/DB.kt b/util/src/main/kotlin/DB.kt @@ -274,9 +274,6 @@ fun connectWithSchema(jdbcConn: String, schemaName: String? = null) { * supported natively by JDBC. */ fun getJdbcConnectionFromPg(pgConn: String): String { - if (pgConn.startsWith("postgres://")) { - throw Exception("only the postgresql:// URI scheme is supported, not postgres://") - } // Pass through jdbc URIs. if (pgConn.startsWith("jdbc:")) { return pgConn @@ -318,5 +315,11 @@ fun getJdbcConnectionFromPg(pgConn: String): String { return "jdbc:postgresql://localhost${parsed.path}?user=$pgUser&socketFactory=org.newsclub.net.unix." + "AFUNIXSocketFactory\$FactoryArg&socketFactoryArg=$socketLocation" } + if (pgConn.startsWith("postgres://")) { + // The JDBC driver doesn't like postgres://, only postgresql://. + // For consistency with other components, we normalize the postgres:// URI + // into one that the JDBC driver likes. + return "jdbc:postgresql://" + pgConn.removePrefix("postgres://") + } return "jdbc:$pgConn" }