commit acfac24086c6963814e500e4a429c8ed5b729c84
parent d4a41ce0aa59b7b599c927c1d1d507cbb075a38d
Author: MS <ms@taler.net>
Date: Fri, 11 Dec 2020 11:29:26 +0100
Database operations.
Handle bad connection string, and show defaults
for the command: reset-table --help.
Diffstat:
4 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -384,7 +384,7 @@ class NexusScheduledTaskEntity(id: EntityID<Int>) : IntEntity(id) {
}
fun dbDropTables(dbConnectionString: String) {
- Database.connect("$dbConnectionString")
+ Database.connect(dbConnectionString)
transaction {
SchemaUtils.drop(
NexusUsersTable,
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -73,10 +73,20 @@ class ParseCamt : CliktCommand("Parse a camt file") {
}
class ResetTables : CliktCommand("Drop all the tables from the database") {
+ init {
+ context {
+ helpFormatter = CliktHelpFormatter(showDefaultValues = true)
+ }
+ }
private val dbConnString by option().default(DEFAULT_DB_CONNECTION)
override fun run() {
- dbDropTables(dbConnString)
- dbCreateTables(dbConnString)
+ try {
+ dbDropTables(dbConnString)
+ dbCreateTables(dbConnString)
+ } catch (e: Exception) {
+ println("Database ($dbConnString) action was unsuccessful")
+ return
+ }
}
}
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -209,7 +209,12 @@ fun requireBankConnection(call: ApplicationCall, parameterKey: String): NexusBan
}
fun serverMain(dbName: String, host: String) {
- dbCreateTables(dbName)
+ try {
+ dbCreateTables(dbName)
+ } catch (e: Exception) {
+ tech.libeufin.util.logger.error("Could not create tables at database: $dbName")
+ return
+ }
val client = HttpClient {
expectSuccess = false // this way, it does not throw exceptions on != 200 responses.
}
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -56,7 +56,9 @@ import io.ktor.http.toHttpDateString
import org.jetbrains.exposed.sql.statements.api.ExposedBlob
import java.time.Instant
import com.github.ajalt.clikt.core.CliktCommand
+import com.github.ajalt.clikt.core.context
import com.github.ajalt.clikt.core.subcommands
+import com.github.ajalt.clikt.output.CliktHelpFormatter
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.option
import io.ktor.request.*
@@ -91,14 +93,29 @@ class SandboxCommand : CliktCommand() {
}
class ResetTables : CliktCommand("Drop all the tables from the database") {
+ init {
+ context {
+ helpFormatter = CliktHelpFormatter(showDefaultValues = true)
+ }
+ }
private val dbConnString by option().default(DEFAULT_DB_CONNECTION)
override fun run() {
- dbDropTables(dbConnString)
- dbCreateTables(dbConnString)
+ try {
+ dbDropTables(dbConnString)
+ dbCreateTables(dbConnString)
+ } catch (e: Exception) {
+ println("Database ($dbConnString) action was unsuccessful")
+ return
+ }
}
}
class Serve : CliktCommand("Run sandbox HTTP server") {
+ init {
+ context {
+ helpFormatter = CliktHelpFormatter(showDefaultValues = true)
+ }
+ }
private val dbConnString by option().default(DEFAULT_DB_CONNECTION)
private val logLevel by option()
override fun run() {
@@ -159,7 +176,12 @@ fun main(args: Array<String>) {
}
fun serverMain(dbName: String) {
- dbCreateTables(dbName)
+ try {
+ dbCreateTables(dbName)
+ } catch (e: Exception) {
+ logger.error("Could not create tables at database: $dbName")
+ return
+ }
val server = embeddedServer(Netty, port = 5000) {
install(CallLogging) {
this.level = Level.DEBUG