Fix enum class Status()
This commit is contained in:
@@ -37,36 +37,44 @@ data class Function(
|
|||||||
)
|
)
|
||||||
|
|
||||||
override fun up(): Status {
|
override fun up(): Status {
|
||||||
try {
|
return try {
|
||||||
connection.sendQuery(up.script)
|
try {
|
||||||
} 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)
|
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 {
|
override fun down(): Status {
|
||||||
connection.sendQuery(down.script)
|
return try {
|
||||||
|
connection.sendQuery(down.script)
|
||||||
|
|
||||||
this::class.java.classLoader
|
this::class.java.classLoader
|
||||||
.getResource("sql/migration/deleteFunction.sql")!!
|
.getResource("sql/migration/deleteFunction.sql")!!
|
||||||
.readText()
|
.readText()
|
||||||
.let { connection.sendQuery(it, listOf(down.name)) }
|
.let { connection.sendQuery(it, listOf(down.name)) }
|
||||||
|
|
||||||
return Status.OK
|
Status.OK
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Status.DOWN_FAIL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun test(): Status {
|
override fun test(): Status {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ interface Migration {
|
|||||||
fun down(): Status
|
fun down(): Status
|
||||||
fun test(): 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 }
|
enum class Action { OK, UP, DOWN }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user