Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.
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
7 changes: 0 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ jobs:
firefox: latest
script: npx aegir test -t browser -- --browsers FirefoxHeadless

- stage: test
name: sharness
os:
- linux
- osx
script: cd ./test/sharness && make

- stage: test
name: electron-main
os: osx
Expand Down
36 changes: 14 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ This package is inspired by the [go-ipfs repo migration tool](https://github.com
- [Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)
- [Usage](#usage)
- [API](#api)
- [`.migrate(path, toVersion, {ignoreLock, repoOptions, onProgress, isDryRun}) -> Promise<void>`](#migratepath-toversion-ignorelock-repooptions-onprogress-isdryrun---promisevoid)
- [`.migrate(path, repoOptions, toVersion, {ignoreLock, onProgress, isDryRun}) -> Promise<void>`](#migratepath-repooptions-toversion-ignorelock-onprogress-isdryrun---promisevoid)
- [`onProgress(migration, counter, totalMigrations)`](#onprogressmigration-counter-totalmigrations)
- [`.revert(path, toVersion, {ignoreLock, repoOptions, onProgress, isDryRun}) -> Promise<void>`](#revertpath-toversion-ignorelock-repooptions-onprogress-isdryrun---promisevoid)
- [`.revert(path, repoOptions, toVersion, {ignoreLock, onProgress, isDryRun}) -> Promise<void>`](#revertpath-repooptions-toversion-ignorelock-onprogress-isdryrun---promisevoid)
- [`getLatestMigrationVersion() -> int`](#getlatestmigrationversion---int)
- [CLI](#cli)
- [Creating a new migration](#creating-a-new-migration)
- [Architecture of a migration](#architecture-of-a-migration)
- [`.migrate(repoPath, repoOptions)`](#migraterepopath-repooptions)
Expand All @@ -50,7 +49,6 @@ This package is inspired by the [go-ipfs repo migration tool](https://github.com

## Background


As js-ipfs evolves and new technologies, algorithms and data structures are incorporated it is necessary to
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/blob/master/REPO.md), [JS implementation](https://github.com/ipfs/js-ipfs-repo) ).
So the IPFS repo is versioned, and this package provides a framework to create migrations to transition
Expand Down Expand Up @@ -93,28 +91,33 @@ const migrations = require('ipfs-repo-migrations')
const repoPath = 'some/repo/path'
const currentRepoVersion = 7
const latestVersion = migrations.getLatestMigrationVersion()
const repoOptions = {
... // the same storage backend/storage options passed to `ipfs-repo`
}

if(currentRepoVersion < latestVersion){
// Old repo! Lets migrate to latest version!
await migrations.migrate(repoPath, latestVersion)
await migrations.migrate(repoPath, latestVersion, {
repoOptions
})
}
```

To migrate your repository using the CLI, see the [how to run migrations](./run.md) tutorial.

## API

### `.migrate(path, toVersion, {ignoreLock, repoOptions, onProgress, isDryRun}) -> Promise<void>`
### `.migrate(path, repoOptions, toVersion, {ignoreLock, onProgress, isDryRun}) -> Promise<void>`

Executes a forward migration to a specific version, or to the latest version if a specific version is not specified.

**Arguments:**

* `path` (string, mandatory) - path to the repo to be migrated
* `repoOptions` (object, mandatory) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
* `toVersion` (int, mandatory) - version to which the repo should be migrated.
* `options` (object, optional) - options for the migration
* `options.ignoreLock` (bool, optional) - if true will not lock the repo when applying migrations. Use with caution.
* `options.repoOptions` (object, optional) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
* `options.onProgress` (function, optional) - callback that is called after finishing execution of each migration to report progress.
* `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.

Expand All @@ -127,35 +130,24 @@ Signature of the progress callback.
* `counter` (int) - index of current migration.
* `totalMigrations` (int) - total count of migrations that will be run.

### `.revert(path, toVersion, {ignoreLock, repoOptions, onProgress, isDryRun}) -> Promise<void>`
### `.revert(path, repoOptions, toVersion, {ignoreLock, onProgress, isDryRun}) -> Promise<void>`

Executes backward migration to a specific version.

**Arguments:**

* `path` (string, mandatory) - path to the repo to be reverted
* `repoOptions` (object, mandatory) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
* `toVersion` (int, mandatory) - version to which the repo should be reverted to.
* `options` (object, optional) - options for the reversion
* `options.ignoreLock` (bool, optional) - if true will not lock the repo when applying migrations. Use with caution.
* `options.repoOptions` (object, optional) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
* `options.onProgress` (function, optional) - callback that is called after finishing execution of each migration to report progress.
* `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.

### `getLatestMigrationVersion() -> int`

Return the version of the latest migration.

## CLI

The CLI is a NodeJS binary named `jsipfs-repo-migrations`.
It has several commands:

* `migrate` - performs forward/backward migration to specific or latest version.
* `status` - check repo for migrations that should be run.
* `add` - bootstraps new migration.

For further details see the `--help` pages.

## Creating a new migration

Migrations are one of those things that can be extremely painful on users. At the end of the day, we want users never to have to think about it. The process should be:
Expand All @@ -174,8 +166,8 @@ be run again.
All migrations are placed in the `/migrations` folder. Each folder there represents one migration that follows the migration
API.

All migrations are collected in `/migrations/index.js`, which should not be edited manually. It is regenerated on
every run of `jsipfs-migrations add` (manual changes should follow the same style of modifications).
All migrations are collected in `/migrations/index.js`, which should not be edited manually.

**The order of migrations is important and migrations must be sorted in ascending order**.

Each migration must follow this API. It must export an object in its `index.js` that has following properties:
Expand Down
8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
"./src/repo/lock.js": "./src/repo/lock-memory.js",
"datastore-fs": "datastore-level"
},
"bin": {
"jsipfs-migrations": "./src/cli.js"
},
"repository": {
"type": "git",
"url": "https://github.com/ipfs/js-ipfs-repo-migrations.git"
Expand All @@ -45,7 +42,6 @@
},
"dependencies": {
"cbor": "^5.0.2",
"chalk": "^4.0.0",
"cids": "^1.0.0",
"datastore-core": "^2.0.0",
"datastore-fs": "^2.0.0",
Expand All @@ -60,9 +56,7 @@
"proper-lockfile": "^4.1.1",
"protons": "^2.0.0",
"uint8arrays": "^1.0.0",
"varint": "^5.0.0",
"yargs": "^15.3.1",
"yargs-promise": "^1.1.0"
"varint": "^5.0.0"
},
"devDependencies": {
"aegir": "^25.0.0",
Expand Down
62 changes: 0 additions & 62 deletions src/cli.js

This file was deleted.

165 changes: 0 additions & 165 deletions src/commands.js

This file was deleted.

15 changes: 15 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,18 @@ class InvalidValueError extends Error {

InvalidValueError.code = 'ERR_INVALID_VALUE'
exports.InvalidValueError = InvalidValueError

/**
* Exception raised when config is not passed.
*/
class MissingRepoOptionsError extends Error {
constructor (message) {
super(message)
this.name = 'MissingRepoOptionsError'
this.code = 'ERR_MISSING_REPO_OPTIONS'
this.message = message
}
}

MissingRepoOptionsError.code = 'ERR_MISSING_REPO_OPTIONS'
exports.MissingRepoOptionsError = MissingRepoOptionsError
Loading