From 54717e5c9630a5ed8bec955f06ba4e2359e20dfc Mon Sep 17 00:00:00 2001 From: MS Date: Tue, 25 Jul 2023 13:13:42 +0200 Subject: Addressing #7890. This allows users to specify (only) PostgreSQL connection strings in the environment. --- sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt | 16 ++++++---------- sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 8 +++++--- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'sandbox/src/main/kotlin/tech/libeufin') diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt index 934dbc4f..523b1bc3 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt @@ -31,12 +31,8 @@ import org.jetbrains.exposed.dao.id.IdTable import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.dao.id.LongIdTable import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.TransactionManager import org.jetbrains.exposed.sql.transactions.transaction -import org.jetbrains.exposed.sql.transactions.transactionManager -import tech.libeufin.sandbox.CashoutSubmissionsTable.nullable import tech.libeufin.util.* -import java.sql.Connection import kotlin.reflect.* import kotlin.reflect.full.* @@ -666,14 +662,14 @@ class CashoutSubmissionEntity(id: EntityID) : LongEntity(id) { var submissionTime by CashoutSubmissionsTable.submissionTime } -fun dbDropTables(dbConnectionString: String) { - connectWithSchema(dbConnectionString) +fun dbDropTables(connStringFromEnv: String) { + connectWithSchema(getJdbcConnectionFromPg(connStringFromEnv)) if (isPostgres()) { val ret = execCommand( listOf( "libeufin-load-sql", "-d", - getDatabaseName(), + connStringFromEnv, "-s", "sandbox", "-r" // the drop option @@ -713,13 +709,13 @@ fun dbDropTables(dbConnectionString: String) { } -fun dbCreateTables(dbConnectionString: String) { - connectWithSchema(dbConnectionString) +fun dbCreateTables(connStringFromEnv: String) { + connectWithSchema(getJdbcConnectionFromPg(connStringFromEnv)) if (isPostgres()) { execCommand(listOf( "libeufin-load-sql", "-d", - getDatabaseName(), + connStringFromEnv, "-s", "sandbox" )) diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt index 42a2a515..bfd521cc 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -231,7 +231,7 @@ class Camt053Tick : CliktCommand( ) { override fun run() { val dbConnString = getDbConnFromEnv(SANDBOX_DB_ENV_VAR_NAME) - dbCreateTables(dbConnString) + execThrowableOrTerminate { dbCreateTables(dbConnString) } val newStatements = mutableMapOf>() /** * For each bank account, extract the latest statement and @@ -293,13 +293,15 @@ class MakeTransaction : CliktCommand("Wire-transfer money between Sandbox bank a private val subjectArg by argument("SUBJECT", "Payment's subject") override fun run() { - val dbConnString = getDbConnFromEnv(SANDBOX_DB_ENV_VAR_NAME) /** * Merely connecting here (and NOT creating any table) because this * command should only be run after actual bank accounts exist in the * system, meaning therefore that the database got already set up. */ - connectWithSchema(dbConnString) + execThrowableOrTerminate { + val pgConnString = getDbConnFromEnv(SANDBOX_DB_ENV_VAR_NAME) + connectWithSchema(getJdbcConnectionFromPg(pgConnString)) + } // Refuse to operate without a default demobank. val demobank = getDemobank("default") if (demobank == null) { -- cgit v1.2.3