From 63a22ef46a57f3b9a7f79fcc04f35dbca1303b2a Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Thu, 1 Aug 2019 01:36:59 +0200 Subject: [PATCH] feature: add forceAllDown to migration --- .../fr/postgresjson/migration/Migrations.kt | 16 +++++++++++++++- src/test/kotlin/fr/postgresjson/MigrationTest.kt | 12 +++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) 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 } } }