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

Commit e819342

Browse files
committed
Check if migration exist for migrate()
1 parent c665a1d commit e819342

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ async function migrate (path, { toVersion, ignoreLock = false, repoOptions, onPr
6363
}
6464
toVersion = toVersion || getLatestMigrationVersion(migrations)
6565

66+
if (toVersion > getLatestMigrationVersion(migrations)) {
67+
throw new errors.InvalidValueError('The ipfs-repo-migrations package does not have migration for version: ' + toVersion)
68+
}
69+
6670
const currentVersion = await repoVersion.getVersion(path)
6771

6872
if (currentVersion === toVersion) {

test/index.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ describe('index.js', () => {
277277
)
278278
})
279279

280+
it('should error if migrations does not exist', () => {
281+
const options = createOptions(5)
282+
283+
return expect(migrator.migrate('/some/path', options))
284+
.to.eventually.be.rejectedWith(errors.InvalidValueError).with.property('code', errors.InvalidValueError.code)
285+
})
286+
280287
it('should use latest migration\'s version if no toVersion is provided', async () => {
281288
const options = createOptions()
282289
getVersionStub.returns(2)

0 commit comments

Comments
 (0)