Minor fix & clean #32

Merged
flecomte merged 6 commits from minor_fix into master 2022-10-14 23:14:03 +02:00
2 changed files with 31 additions and 23 deletions
Showing only changes of commit 54a628c742 - Show all commits

View File

@@ -37,36 +37,44 @@ data class Function(
)
override fun up(): Status {
try {
connection.sendQuery(up.script)
} catch (e: CompletionException) {
val cause = e.cause
if (cause is GenericDatabaseException && cause.errorMessage.fields['C'] == "42P13") {
connection.sendQuery("drop function ${down.getDefinition()}")
return try {
try {
connection.sendQuery(up.script)
} catch (e: CompletionException) {
val cause = e.cause
if (cause is GenericDatabaseException && cause.errorMessage.fields['C'] == "42P13") {
connection.sendQuery("drop function ${down.getDefinition()}")
connection.sendQuery(up.script)
}
}
this::class.java.classLoader
.getResource("sql/migration/insertFunction.sql")!!.readText()
.let { connection.selectOne<MigrationEntity>(it, listOf(up.name, up.getDefinition(), up.script, down.script)) }
?.let { function ->
executedAt = function.executedAt
doExecute = Action.OK
}
Status.OK
} catch (e: Throwable) {
Status.UP_FAIL
}
this::class.java.classLoader
.getResource("sql/migration/insertFunction.sql")!!.readText()
.let { connection.selectOne<MigrationEntity>(it, listOf(up.name, up.getDefinition(), up.script, down.script)) }
?.let { function ->
executedAt = function.executedAt
doExecute = Action.OK
}
return Status.OK
}
override fun down(): Status {
connection.sendQuery(down.script)
return try {
connection.sendQuery(down.script)
this::class.java.classLoader
.getResource("sql/migration/deleteFunction.sql")!!
.readText()
.let { connection.sendQuery(it, listOf(down.name)) }
this::class.java.classLoader
.getResource("sql/migration/deleteFunction.sql")!!
.readText()
.let { connection.sendQuery(it, listOf(down.name)) }
return Status.OK
Status.OK
} catch (e: Throwable) {
Status.DOWN_FAIL
}
}
override fun test(): Status {

View File

@@ -29,7 +29,7 @@ interface Migration {
fun down(): Status
fun test(): Status
enum class Status(i: Int) { OK(2), UP_FAIL(0), DOWN_FAIL(1) }
enum class Status(val i: Int) { OK(2), UP_FAIL(0), DOWN_FAIL(1) }
enum class Action { OK, UP, DOWN }
}