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

fix: migrate empty repos #35

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions migrations/migration-9/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
15 changes: 15 additions & 0 deletions test/migrations/migration-8-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env mocha */
/* eslint-disable max-nested-callbacks */
'use strict'

const { expect } = require('aegir/utils/chai')
Expand Down Expand Up @@ -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, () => {})
Expand Down
14 changes: 14 additions & 0 deletions test/migrations/migration-9-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down