Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit b64412b

Browse files
committed
Improving verification of reversibility
License: MIT Signed-off-by: Adam Uhlir <uhlir.a@gmail.com>
1 parent 966080f commit b64412b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,31 @@ exports.revert = revert
185185

186186
/**
187187
* Function checks if all migrations in given range supports reversion.
188+
* fromVersion > toVersion
188189
*
189190
* @param {array} migrations
190191
* @param {int} fromVersion
191192
* @param {int} toVersion
192193
* @returns {object}
193194
*/
194195
function verifyReversibility (migrations, fromVersion, toVersion) {
196+
let migrationCounter = 0
195197
for (let migration of migrations) {
196198
if (migration.version > fromVersion) {
197199
break
198200
}
199201

200-
if (migration.version >= toVersion && !migration.reversible) {
201-
return { reversible: false, version: migration.version }
202+
if (migration.version >= toVersion) {
203+
migrationCounter++
204+
205+
if (!migration.reversible)
206+
return { reversible: false, version: migration.version }
202207
}
203208
}
204209

205-
return { reversible: true, version: undefined }
210+
if (migrationCounter !== (fromVersion - toVersion)){
211+
throw new Error('There are missing migration to perform the reversion!')
212+
}
213+
214+
return { reversible: true, version: undefined }
206215
}

0 commit comments

Comments
 (0)