diff --git a/src/main/kotlin/fr/postgresjson/migration/Migrations.kt b/src/main/kotlin/fr/postgresjson/migration/Migrations.kt index 915a82a..96923ef 100644 --- a/src/main/kotlin/fr/postgresjson/migration/Migrations.kt +++ b/src/main/kotlin/fr/postgresjson/migration/Migrations.kt @@ -227,7 +227,7 @@ data class Migrations private constructor( up().map { list[Pair(it.key, Direction.UP)] = it.value } - down(true).map { + down().map { list[Pair(it.key, Direction.DOWN)] = it.value } sendQuery("COMMIT") @@ -240,6 +240,20 @@ data class Migrations private constructor( return this.copy().runTest() } + fun forceAllDown(): Map, Status> { + val list: MutableMap, Status> = mutableMapOf() + connection.apply { + sendQuery("BEGIN") + lock() + down(true).map { + list[Pair(it.key, Direction.DOWN)] = it.value + } + sendQuery("COMMIT") + } + + return list.toMap() + } + private fun runTest(): Map, Status> { val list: MutableMap, Status> = mutableMapOf() connection.apply { diff --git a/src/test/kotlin/fr/postgresjson/MigrationTest.kt b/src/test/kotlin/fr/postgresjson/MigrationTest.kt index 061781a..860b5da 100644 --- a/src/test/kotlin/fr/postgresjson/MigrationTest.kt +++ b/src/test/kotlin/fr/postgresjson/MigrationTest.kt @@ -69,7 +69,17 @@ class MigrationTest(): TestAbstract() { val resources = File(this::class.java.getResource("/sql/real_migrations").toURI()) Migrations(resources, getConnextion()).apply { run().apply { - size `should be equal to` 2 + size `should be equal to` 1 + } + } + } + + @Test + fun `run migrations force down`() { + val resources = File(this::class.java.getResource("/sql/real_migrations").toURI()) + Migrations(resources, getConnextion()).apply { + forceAllDown().apply { + size `should be equal to` 1 } } }