feature #2: save executed migration in DB
This commit is contained in:
@@ -2,6 +2,8 @@ package fr.postgresjson.migration
|
||||
|
||||
import fr.postgresjson.connexion.Connection
|
||||
import fr.postgresjson.entity.Entity
|
||||
import fr.postgresjson.migration.Migration.Action
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class Query(
|
||||
@@ -11,16 +13,27 @@ class Query(
|
||||
private val connection: Connection,
|
||||
override var executedAt: Date? = null
|
||||
): Migration, Entity<String?>(name) {
|
||||
override var doExecute: Action? = null
|
||||
|
||||
override fun up(): Migration.Status {
|
||||
connection.exec(up).join()
|
||||
// TODO insert to migration Table
|
||||
|
||||
File(this::class.java.getResource("/sql/migration/insertHistory.sql").toURI()).let {
|
||||
connection.selectOne<String, MigrationEntity?>(it.readText(), listOf(name, up, down))?.let { query ->
|
||||
executedAt = query.executedAt
|
||||
doExecute = Action.OK
|
||||
}
|
||||
}
|
||||
|
||||
return Migration.Status.OK
|
||||
}
|
||||
|
||||
override fun down(): Migration.Status {
|
||||
connection.exec(down).join()
|
||||
// TODO insert to migration Table
|
||||
|
||||
File(this::class.java.getResource("/sql/migration/deleteHistory.sql").toURI()).let {
|
||||
connection.exec(it.readText(), listOf(name))
|
||||
}
|
||||
|
||||
return Migration.Status.OK
|
||||
}
|
||||
@@ -44,8 +57,4 @@ class Query(
|
||||
|
||||
return Migration.Status.OK // TODO
|
||||
}
|
||||
|
||||
override fun doExecute(): Boolean {
|
||||
return executedAt === null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user