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

Commit d1faaa2

Browse files
authored
fix: require passing repo options to migrator (#30)
In order to successfully open a datastore we should accept config that tells us how to open the datastore. Refs: ipld/explore.ipld.io#65
1 parent c1e6403 commit d1faaa2

22 files changed

+314
-632
lines changed

.travis.yml

-7
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ jobs:
3737
firefox: latest
3838
script: npx aegir test -t browser -- --browsers FirefoxHeadless
3939

40-
- stage: test
41-
name: sharness
42-
os:
43-
- linux
44-
- osx
45-
script: cd ./test/sharness && make
46-
4740
- stage: test
4841
name: electron-main
4942
os: osx

README.md

+21-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Migration tool for JS IPFS Repo
1+
# Migration tool for JS IPFS Repo <!-- omit in toc -->
22

33
[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-repo-migrations)](https://travis-ci.com/ipfs/js-ipfs-repo-migrations)
44
[![codecov](https://codecov.io/gh/ipfs/js-ipfs-repo-migrations/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-ipfs-repo-migrations)
@@ -15,36 +15,41 @@
1515
1616
This package is inspired by the [go-ipfs repo migration tool](https://github.com/ipfs/fs-repo-migrations/)
1717

18-
## Lead Maintainer
18+
## Lead Maintainer <!-- omit in toc -->
1919

2020
[Adam Uhlíř](https://github.com/auhau/)
2121

22-
## Table of Contents
22+
## Table of Contents <!-- omit in toc -->
2323

2424
- [Background](#background)
2525
- [Install](#install)
2626
- [npm](#npm)
2727
- [Use in Node.js](#use-in-nodejs)
2828
- [Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)
29-
- [Use in a browser Using a script tag](#use-in-a-browser-using-a-script-tag)
3029
- [Usage](#usage)
3130
- [API](#api)
31+
- [`.migrate(path, toVersion, {ignoreLock, repoOptions, onProgress, isDryRun}) -> Promise<void>`](#migratepath-toversion-ignorelock-repooptions-onprogress-isdryrun---promisevoid)
32+
- [`onProgress(migration, counter, totalMigrations)`](#onprogressmigration-counter-totalmigrations)
33+
- [`.revert(path, toVersion, {ignoreLock, repoOptions, onProgress, isDryRun}) -> Promise<void>`](#revertpath-toversion-ignorelock-repooptions-onprogress-isdryrun---promisevoid)
34+
- [`getLatestMigrationVersion() -> int`](#getlatestmigrationversion---int)
3235
- [CLI](#cli)
3336
- [Creating a new migration](#creating-a-new-migration)
3437
- [Architecture of a migration](#architecture-of-a-migration)
38+
- [`.migrate(repoPath, repoOptions)`](#migraterepopath-repooptions)
39+
- [`.revert(repoPath, repoOptions)`](#revertrepopath-repooptions)
3540
- [Browser vs. NodeJS environments](#browser-vs-nodejs-environments)
3641
- [Guidelines](#guidelines)
3742
- [Integration with js-ipfs](#integration-with-js-ipfs)
43+
- [Tests](#tests)
3844
- [Empty migrations](#empty-migrations)
3945
- [Migrations matrix](#migrations-matrix)
4046
- [Developer](#developer)
41-
- [Module versioning notes](#module-versioning-notes)
47+
- [Module versioning notes](#module-versioning-notes)
4248
- [Contribute](#contribute)
4349
- [License](#license)
4450

4551
## Background
4652

47-
4853
As js-ipfs evolves and new technologies, algorithms and data structures are incorporated it is necessary to
4954
enable users to transition between versions. Different versions of js-ipfs may expect a different IPFS repo structure or content (see: [IPFS repo spec](https://github.com/ipfs/specs/tree/master/repo), [JS implementation](https://github.com/ipfs/js-ipfs-repo) ).
5055
So the IPFS repo is versioned, and this package provides a framework to create migrations to transition
@@ -87,10 +92,15 @@ const migrations = require('ipfs-repo-migrations')
8792
const repoPath = 'some/repo/path'
8893
const currentRepoVersion = 7
8994
const latestVersion = migrations.getLatestMigrationVersion()
95+
const repoOptions = {
96+
... // the same storage backend/storage options passed to `ipfs-repo`
97+
}
9098

9199
if(currentRepoVersion < latestVersion){
92100
// Old repo! Lets migrate to latest version!
93-
await migrations.migrate(repoPath, latestVersion)
101+
await migrations.migrate(repoPath, latestVersion, {
102+
repoOptions
103+
})
94104
}
95105
```
96106

@@ -106,9 +116,9 @@ Executes a forward migration to a specific version, or to the latest version if
106116

107117
* `path` (string, mandatory) - path to the repo to be migrated
108118
* `toVersion` (int, mandatory) - version to which the repo should be migrated.
109-
* `options` (object, optional) - options for the migration
119+
* `options` (object, mandatory) - options for the migration
110120
* `options.ignoreLock` (bool, optional) - if true will not lock the repo when applying migrations. Use with caution.
111-
* `options.repoOptions` (object, optional) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
121+
* `options.repoOptions` (object, mandatory) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
112122
* `options.onProgress` (function, optional) - callback that is called after finishing execution of each migration to report progress.
113123
* `options.isDryRun` (bool, optional) - flag that indicates if it is a dry run that should give the same output as running a migration but without making any actual changes.
114124

@@ -129,9 +139,9 @@ Executes backward migration to a specific version.
129139

130140
* `path` (string, mandatory) - path to the repo to be reverted
131141
* `toVersion` (int, mandatory) - version to which the repo should be reverted to.
132-
* `options` (object, optional) - options for the reversion
142+
* `options` (object, mandatory) - options for the reversion
133143
* `options.ignoreLock` (bool, optional) - if true will not lock the repo when applying migrations. Use with caution.
134-
* `options.repoOptions` (object, optional) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
144+
* `options.repoOptions` (object, mandatory) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
135145
* `options.onProgress` (function, optional) - callback that is called after finishing execution of each migration to report progress.
136146
* `options.isDryRun` (bool, optional) - flag that indicates if it is a dry run that should give the same output as running a migration but without making any actual changes.
137147

package.json

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
"main": "src/index.js",
2121
"browser": {
2222
"./src/repo/lock.js": "./src/repo/lock-memory.js",
23+
"./src/repo/default-root-options.js": "./src/repo/ldefault-root-options.browser.js",
2324
"datastore-fs": "datastore-level"
2425
},
25-
"bin": {
26-
"jsipfs-migrations": "./src/cli.js"
27-
},
2826
"repository": {
2927
"type": "git",
3028
"url": "https://github.com/ipfs/js-ipfs-repo-migrations.git"
@@ -45,17 +43,14 @@
4543
},
4644
"dependencies": {
4745
"buffer": "^5.6.0",
48-
"chalk": "^4.0.0",
4946
"cids": "^0.8.3",
5047
"datastore-core": "^1.1.0",
5148
"datastore-fs": "^1.0.0",
5249
"datastore-level": "^1.1.0",
5350
"debug": "^4.1.0",
5451
"interface-datastore": "^1.0.2",
5552
"multibase": "^1.0.1",
56-
"proper-lockfile": "^4.1.1",
57-
"yargs": "^15.3.1",
58-
"yargs-promise": "^1.1.0"
53+
"proper-lockfile": "^4.1.1"
5954
},
6055
"devDependencies": {
6156
"aegir": "^23.0.0",

src/cli.js

-62
This file was deleted.

src/commands.js

-165
This file was deleted.

src/errors.js

+15
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,18 @@ class InvalidValueError extends Error {
6060

6161
InvalidValueError.code = 'ERR_INVALID_VALUE'
6262
exports.InvalidValueError = InvalidValueError
63+
64+
/**
65+
* Exception raised when config is not passed.
66+
*/
67+
class MissingRepoOptionsError extends Error {
68+
constructor (message) {
69+
super(message)
70+
this.name = 'MissingRepoOptionsError'
71+
this.code = 'ERR_MISSING_REPO_OPTIONS'
72+
this.message = message
73+
}
74+
}
75+
76+
MissingRepoOptionsError.code = 'ERR_MISSING_REPO_OPTIONS'
77+
exports.MissingRepoOptionsError = MissingRepoOptionsError

0 commit comments

Comments
 (0)