feature: get migrations from DB

This commit is contained in:
2019-07-02 17:28:52 +02:00
parent 551a6c11cd
commit f48b06b596
5 changed files with 191 additions and 77 deletions

View File

@@ -1,41 +1,51 @@
package fr.postgresjson.migration
import fr.postgresjson.connexion.Connection
import fr.postgresjson.entity.Entity
import java.util.*
class Query(
val name: String,
val up: String,
val down: String,
private val connection: Connection
): Migration {
enum class Status(i: Int) { OK(2), UP_FAIL(0), DOWN_FAIL(1) }
override fun up(): Int {
private val connection: Connection,
override var executedAt: Date? = null
): Migration, Entity<String?>(name) {
override fun up(): Migration.Status {
connection.exec(up)
return 1
// TODO insert to migration Table
return Migration.Status.OK
}
override fun down(): Int {
override fun down(): Migration.Status {
connection.exec(down)
return 1
// TODO insert to migration Table
return Migration.Status.OK
}
override fun test(): Int {
override fun test(): Migration.Status {
connection.inTransaction {
connection.exec(up)
connection.exec(down)
up()
down()
it.sendQuery("ROLLBACK");
}
return 1
}.join()
return Migration.Status.OK // TODO
}
override fun status(): Int {
override fun status(): Migration.Status {
val result = connection.inTransaction {
connection.exec(up)
connection.exec(down)
up()
down()
it.sendQuery("ROLLBACK")
}.join()
return result.rowsAffected.toInt()
return Migration.Status.OK // TODO
}
override fun doExecute(): Boolean {
return executedAt === null
}
}