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

Commit b0fd1c9

Browse files
committed
chore: re-pr #30 against master
Adds the changes released in `1.0.1` to master.
1 parent 69d08fe commit b0fd1c9

File tree

5 files changed

+95
-48
lines changed

5 files changed

+95
-48
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This package is inspired by the [go-ipfs repo migration tool](https://github.com
3030
- [API](#api)
3131
- [`.migrate(path, toVersion, {ignoreLock, repoOptions, onProgress, isDryRun}) -> Promise<void>`](#migratepath-toversion-ignorelock-repooptions-onprogress-isdryrun---promisevoid)
3232
- [`onProgress(migration, counter, totalMigrations)`](#onprogressmigration-counter-totalmigrations)
33-
- [`.revert(path, toVersion, {ignoreLock, repoOptions, onProgress, isDryRun}) -> Promise<void>`](#revertpath-toversion-ignorelock-repooptions-onprogress-isdryrun---promisevoid)
33+
- [`.revert(path, repoOptions, toVersion, {ignoreLock, onProgress, isDryRun}) -> Promise<void>`](#revertpath-repooptions-toversion-ignorelock-onprogress-isdryrun---promisevoid)
3434
- [`getLatestMigrationVersion() -> int`](#getlatestmigrationversion---int)
3535
- [CLI](#cli)
3636
- [Creating a new migration](#creating-a-new-migration)
@@ -115,10 +115,10 @@ Executes a forward migration to a specific version, or to the latest version if
115115
**Arguments:**
116116

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

@@ -131,17 +131,17 @@ Signature of the progress callback.
131131
* `counter` (int) - index of current migration.
132132
* `totalMigrations` (int) - total count of migrations that will be run.
133133

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

136136
Executes backward migration to a specific version.
137137

138138
**Arguments:**
139139

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

src/index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,27 @@ exports.getLatestMigrationVersion = getLatestMigrationVersion
3636
* Signature of the progress callback is: function(migrationObject: object, currentMigrationNumber: int, totalMigrationsCount: int)
3737
*
3838
* @param {string} path - Path to initialized (!) JS-IPFS repo
39+
* @param {Object} repoOptions - Options that are passed to migrations, that can use them to correctly construct datastore. Options are same like for IPFSRepo.
3940
* @param {int} toVersion - Version to which the repo should be migrated.
40-
* @param {Object} options - Options for migration
41+
* @param {Object?} options - Options for migration
4142
* @param {boolean?} options.ignoreLock - Won't lock the repo for applying the migrations. Use with caution.
42-
* @param {object?} options.repoOptions - Options that are passed to migrations, that can use them to correctly construct datastore. Options are same like for IPFSRepo.
4343
* @param {function?} options.onProgress - Callback which will be called after each executed migration to report progress
4444
* @param {boolean?} options.isDryRun - Allows to simulate the execution of the migrations without any effect.
4545
* @param {array?} options.migrations - Array of migrations to migrate. If undefined, the bundled migrations are used. Mainly for testing purpose.
4646
* @returns {Promise<void>}
4747
*/
48-
async function migrate (path, toVersion, { ignoreLock = false, repoOptions, onProgress, isDryRun = false, migrations }) {
48+
async function migrate (path, repoOptions, toVersion, { ignoreLock = false, onProgress, isDryRun = false, migrations }) {
4949
migrations = migrations || defaultMigrations
5050
onProgress = onProgress || (() => {})
5151

5252
if (!path) {
5353
throw new errors.RequiredParameterError('Path argument is required!')
5454
}
5555

56+
if (!repoOptions) {
57+
throw new errors.RequiredParameterError('repoOptions argument is required!')
58+
}
59+
5660
if (!toVersion) {
5761
throw new errors.RequiredParameterError('toVersion argument is required!')
5862
}
@@ -121,23 +125,27 @@ exports.migrate = migrate
121125
* Signature of the progress callback is: function(migrationObject: object, currentMigrationNumber: int, totalMigrationsCount: int)
122126
*
123127
* @param {string} path - Path to initialized (!) JS-IPFS repo
128+
* @param {Object} repoOptions - Options that are passed to migrations, that can use them to correctly construct datastore. Options are same like for IPFSRepo.
124129
* @param {int} toVersion - Version to which the repo will be reverted.
125-
* @param {Object} options - Options for the reversion
130+
* @param {Object?} options - Options for the reversion
126131
* @param {function?} options.onProgress - Callback which will be called after each reverted migration to report progress
127-
* @param {object?} options.repoOptions - Options that are passed to migrations, that can use them to correctly construct datastore. Options are same like for IPFSRepo.
128132
* @param {boolean?} options.isDryRun - Allows to simulate the execution of the reversion without any effects. Make sense to utilize onProgress with this argument.
129133
* @param {boolean?} options.ignoreLock - Won't lock the repo for reverting the migrations. Use with caution.
130134
* @param {array?} options.migrations - Array of migrations to migrate. If undefined, the bundled migrations are used. Mainly for testing purpose.
131135
* @returns {Promise<void>}
132136
*/
133-
async function revert (path, toVersion, { ignoreLock = false, repoOptions, onProgress, isDryRun = false, migrations }) {
137+
async function revert (path, repoOptions, toVersion, { ignoreLock = false, onProgress, isDryRun = false, migrations }) {
134138
migrations = migrations || defaultMigrations
135139
onProgress = onProgress || (() => {})
136140

137141
if (!path) {
138142
throw new errors.RequiredParameterError('Path argument is required!')
139143
}
140144

145+
if (!repoOptions) {
146+
throw new errors.RequiredParameterError('repoOptions argument is required!')
147+
}
148+
141149
if (!toVersion) {
142150
throw new errors.RequiredParameterError('When reverting migrations, you have to specify to which version to revert!')
143151
}

src/repo/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const repoInit = require('./init')
44
const { MissingRepoOptionsError, NotInitializedRepoError } = require('../errors')
55
const { VERSION_KEY, getDatastoreAndOptions } = require('../utils')
6-
const repoInit = require('./init')
6+
const uint8ArrayFromString = require('uint8arrays/from-string')
77

88
exports.getVersion = getVersion
99

0 commit comments

Comments
 (0)