fix: functions migrations

This commit is contained in:
2019-08-02 20:39:30 +02:00
parent 56a141a34c
commit 88d581c529
7 changed files with 54 additions and 8 deletions

View File

@@ -37,7 +37,7 @@ data class Function(
connection.sendQuery(up.script)
this::class.java.classLoader.getResource("sql/migration/insertFunction.sql")!!.readText().let {
connection.selectOne<MigrationEntity>(it, listOf(up))?.let { function ->
connection.selectOne<MigrationEntity>(it, listOf(up.name, up.getDefinition(), up.script, down.script))?.let { function ->
executedAt = function.executedAt
doExecute = Action.OK
}

View File

@@ -37,10 +37,12 @@ data class Migrations private constructor(
private val queries: MutableMap<String, Query> = mutableMapOf(),
private val functions: MutableMap<String, Function> = mutableMapOf()
) {
constructor(directory: File, connection: Connection): this(connection) {
constructor(directory: File, connection: Connection): this(listOf(directory), connection)
constructor(directories: List<File>, connection: Connection): this(connection) {
initDB()
getMigrationFromDB()
getMigrationFromDirectory(directory)
getMigrationFromDirectory(directories)
queries.forEach { (_, query) ->
if (query.doExecute === null) {
query.doExecute = Action.DOWN
@@ -75,6 +77,15 @@ data class Migrations private constructor(
}
}
/**
* Get all migration from multiples Directories
*/
private fun getMigrationFromDirectory(directory: List<File>) {
directory.forEach {
getMigrationFromDirectory(it)
}
}
/**
* Get all migration from Directory
*/