Add ShadowJar compatibility and Query file can be define name with comment
Add Migration and Query definition class Add Docker DB for tests
This commit is contained in:
35
src/main/kotlin/fr/postgresjson/definition/Migration.kt
Normal file
35
src/main/kotlin/fr/postgresjson/definition/Migration.kt
Normal file
@@ -0,0 +1,35 @@
|
||||
package fr.postgresjson.definition
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
class Migration(
|
||||
override val script: String,
|
||||
source: Path
|
||||
) : Resource {
|
||||
override val name: String
|
||||
val direction: Direction
|
||||
override var source: Path? = null
|
||||
|
||||
init {
|
||||
this.source = source
|
||||
this.direction = source.fileName.toString()
|
||||
.let {
|
||||
when {
|
||||
it.endsWith(".down.sql") -> Direction.DOWN
|
||||
it.endsWith(".up.sql") -> Direction.UP
|
||||
else -> throw MigrationNotFound()
|
||||
}
|
||||
}
|
||||
this.name = source.fileName.toString()
|
||||
.substringAfterLast("/")
|
||||
.let {
|
||||
when (direction) {
|
||||
Direction.DOWN -> it.substringBefore(".down.sql")
|
||||
Direction.UP -> it.substringBefore(".up.sql")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MigrationNotFound(cause: Throwable? = null) : Resource.ParseException("Migration not found in script", cause)
|
||||
enum class Direction { UP, DOWN }
|
||||
}
|
||||
Reference in New Issue
Block a user