Skip to content

Commit 712ed2a

Browse files
authored
fix: open datastores after migration (#255)
Otherwise they can mess up migrations
1 parent 6166e1f commit 712ed2a

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

.aegir.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ module.exports = {
44
webpack: {
55
node: {
66
// this is needed until level stops using node buffers in browser code
7-
Buffer: true
7+
Buffer: true,
8+
9+
// needed by binary-parse-stream
10+
stream: true
811
}
912
}
1013
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"debug": "^4.1.0",
6565
"err-code": "^2.0.0",
6666
"interface-datastore": "^2.0.0",
67-
"ipfs-repo-migrations": "^5.0.1",
67+
"ipfs-repo-migrations": "^5.0.2",
6868
"ipfs-utils": "^2.3.1",
6969
"ipld-block": "^0.10.0",
7070
"it-map": "^1.0.2",

src/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict'
22

33
module.exports = {
4-
repoVersion: 8
4+
repoVersion: 9
55
}

src/index.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ class IpfsRepo {
111111
await this._checkInitialized()
112112
this.lockfile = await this._openLock(this.path)
113113
log('acquired repo.lock')
114+
115+
const isCompatible = await this.version.check(constants.repoVersion)
116+
117+
if (!isCompatible) {
118+
if (await this._isAutoMigrationEnabled()) {
119+
await this._migrate(constants.repoVersion)
120+
} else {
121+
throw new ERRORS.InvalidRepoVersionError('Incompatible repo versions. Automatic migrations disabled. Please migrate the repo manually.')
122+
}
123+
}
124+
114125
log('creating datastore')
115126
this.datastore = backends.create('datastore', pathJoin(this.path, 'datastore'), this.options)
116127
await this.datastore.open()
@@ -125,15 +136,6 @@ class IpfsRepo {
125136
this.pins = backends.create('pins', pathJoin(this.path, 'pins'), this.options)
126137
await this.pins.open()
127138

128-
const isCompatible = await this.version.check(constants.repoVersion)
129-
if (!isCompatible) {
130-
if (await this._isAutoMigrationEnabled()) {
131-
await this._migrate(constants.repoVersion)
132-
} else {
133-
throw new ERRORS.InvalidRepoVersionError('Incompatible repo versions. Automatic migrations disabled. Please migrate the repo manually.')
134-
}
135-
}
136-
137139
this.closed = false
138140
log('all opened')
139141
} catch (err) {

test/interop-test.js

-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ module.exports = (repo) => {
2929
expect(values.map((value) => value.data.length)).to.eql([2659, 12783])
3030
})
3131

32-
it('reads pin set from the datastore', async () => {
33-
const val = await repo.datastore.get(new Key('/local/pins'))
34-
expect(mh.toB58String(val)).to.equal('QmYAuyf2LzMba65NnhxLtGJxixKNUev9qYSu4MYM88hdwK')
35-
})
36-
3732
it('reads DHT records from the datastore', async () => {
3833
const val = await repo.datastore.get(new Key('/AHE5I5B7TY'))
3934
expect(uint8ArrayToString(val, 'base16')).to.eql('0a0601c9d4743f9e12097465737476616c75651a2212201d22e2a5e140e5cd20d88fc59cd560f4887c7d9acf938ddb24d7207eac40fd2f')

test/repo-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ module.exports = (repo) => {
5656

5757
describe('version', () => {
5858
afterEach(async () => {
59-
await repo.version.set(8)
59+
await repo.version.set(9)
6060
})
6161

6262
it('get version', async () => {
6363
const version = await repo.version.get()
64-
expect(version).to.equal(8)
64+
expect(version).to.equal(9)
6565
})
6666

6767
it('set version', async () => {

0 commit comments

Comments
 (0)