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

Commit c665a1d

Browse files
committed
Non-throw error handling for getLatestMigrationVersion
1 parent 6715d0d commit c665a1d

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exports.errors = errors
1414

1515
/**
1616
* Returns the version of latest migration.
17+
* If no migrations are present returns 0.
1718
*
1819
* @param {array?} migrations - Array of migrations to consider. If undefined, the bundled migrations are used. Mainly for testing purpose.
1920
* @returns {int}
@@ -22,7 +23,7 @@ function getLatestMigrationVersion (migrations) {
2223
migrations = migrations || defaultMigrations
2324

2425
if (!Array.isArray(migrations) || migrations.length === 0) {
25-
throw new errors.InvalidValueError('Migrations must be non-empty array!')
26+
return 0
2627
}
2728

2829
return migrations[migrations.length - 1].version

test/index.spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ describe('index.js', () => {
8080
const migrationsMock = createMigrations()
8181

8282
expect(migrator.getLatestMigrationVersion(migrationsMock)).to.equal(4)
83-
84-
expect(
85-
() => migrator.getLatestMigrationVersion([])
86-
).to.throw(errors.InvalidValueError).with.property('code', errors.InvalidValueError.code)
83+
expect(migrator.getLatestMigrationVersion([])).to.equal(0)
8784
})
8885

8986
describe('revert', () => {

0 commit comments

Comments
 (0)