diff --git a/migrations/migration-9/index.js b/migrations/migration-9/index.js index 0507711..57d52e9 100644 --- a/migrations/migration-9/index.js +++ b/migrations/migration-9/index.js @@ -11,6 +11,10 @@ const { cidToKey, PIN_DS_KEY, PinTypes } = require('./utils') const length = require('it-length') async function pinsToDatastore (blockstore, datastore, pinstore, onProgress) { + if (!await datastore.has(PIN_DS_KEY)) { + return + } + const mh = await datastore.get(PIN_DS_KEY) const cid = new CID(mh) const pinRootBuf = await blockstore.get(cidToKey(cid)) diff --git a/src/index.js b/src/index.js index d38e7e9..d5089e7 100644 --- a/src/index.js +++ b/src/index.js @@ -107,11 +107,11 @@ async function migrate (path, repoOptions, toVersion, { ignoreLock = false, onPr } } catch (e) { const lastSuccessfullyMigratedVersion = migration.version - 1 + log(`An exception was raised during execution of migration. Setting the repo's version to last successfully migrated version: ${lastSuccessfullyMigratedVersion}`) await repoVersion.setVersion(path, lastSuccessfullyMigratedVersion, repoOptions) - e.message = `During migration to version ${migration.version} exception was raised: ${e.message}` - throw e + throw new Error(`During migration to version ${migration.version} exception was raised: ${e.stack || e.message || e}`) } log(`Migrating to version ${migration.version} finished`) diff --git a/test/migrations/migration-8-test.js b/test/migrations/migration-8-test.js index 4b2f280..1dc120d 100644 --- a/test/migrations/migration-8-test.js +++ b/test/migrations/migration-8-test.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +/* eslint-disable max-nested-callbacks */ 'use strict' const { expect } = require('aegir/utils/chai') @@ -89,6 +90,20 @@ module.exports = (setup, cleanup, repoOptions) => { await cleanup(dir) }) + describe('empty repo', () => { + describe('forwards', () => { + it('should migrate pins forward', async () => { + await migration.migrate(dir, repoOptions, () => {}) + }) + }) + + describe('backwards', () => { + it('should migrate pins backward', async () => { + await migration.revert(dir, repoOptions, () => {}) + }) + }) + }) + it('should migrate blocks forward', async () => { await bootstrapBlocks(dir, false, repoOptions) await migration.migrate(dir, repoOptions, () => {}) diff --git a/test/migrations/migration-9-test.js b/test/migrations/migration-9-test.js index b20fd70..a8a981f 100644 --- a/test/migrations/migration-9-test.js +++ b/test/migrations/migration-9-test.js @@ -121,6 +121,20 @@ module.exports = (setup, cleanup, repoOptions) => { await cleanup(dir) }) + describe('empty repo', () => { + describe('forwards', () => { + it('should migrate pins forward', async () => { + await migration.migrate(dir, repoOptions, () => {}) + }) + }) + + describe('backwards', () => { + it('should migrate pins backward', async () => { + await migration.revert(dir, repoOptions, () => {}) + }) + }) + }) + Object.keys(pinsets).forEach(title => { const pinset = pinsets[title] const pinned = {}