You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 1, 2021. It is now read-only.
Executes a forward migration to a specific version, or to the latest version if a specific version is not specified.
98
+
99
+
**Arguments:**
100
+
101
+
*`path` (string, mandatory) - path to the repo to be migrated
102
+
*`options` (object, optional) - options for the migration
103
+
*`options.toVersion` (int, optional) - version to which the repo should be migrated. Defaults to the latest migration version.
104
+
*`options.ignoreLock` (bool, optional) - if true will not lock the repo when applying migrations. Use with caution.
105
+
*`options.repoOptions` (object, optional) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
106
+
*`options.onProgress` (function, optional) - callback that is called after finishing execution of each migration to report progress.
107
+
*`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.
*`migration` (object) - object of migration that just successfully finished running. See [Architecture of migrations](#architecture-of-migrations) for details.
115
+
*`counter` (int) - index of current migration.
116
+
*`totalMigrations` (int) - total count of migrations that will be run.
Executes backward migration to a specific version.
121
+
122
+
**Arguments:**
123
+
124
+
*`path` (string, mandatory) - path to the repo to be reverted
125
+
*`toVersion` (int, mandatory) - version to which the repo should be reverted to.
126
+
*`options` (object, optional) - options for the reversion
127
+
*`options.ignoreLock` (bool, optional) - if true will not lock the repo when applying migrations. Use with caution.
128
+
*`options.options` (object, optional) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
129
+
*`options.onProgress` (function, optional) - callback that is called after finishing execution of each migration to report progress.
130
+
*`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.
131
+
132
+
### `getLatestMigrationVersion() -> int`
95
133
96
-
### Writing migration
134
+
Return the version of the latest migration.
135
+
136
+
## CLI
137
+
138
+
The CLI is a NodeJS binary named `jsipfs-repo-migrations`.
139
+
It has several commands:
140
+
141
+
*`migrate` - performs forward/backward migration to specific or latest version.
142
+
*`status` - check repo for migrations that should be run.
143
+
*`add` - bootstraps new migration.
144
+
145
+
For further details see the `--help` pages.
146
+
147
+
## Creating a new migration
97
148
98
149
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:
99
150
@@ -106,7 +157,7 @@ If your migration has several parts, it should be fail-proof enough that if one
106
157
are reverted before propagating the error. If possible then the outcome should be consistent repo so it migration could
107
158
be run again.
108
159
109
-
####Architecture of migrations
160
+
### Architecture of a migration
110
161
111
162
All migrations are placed in the `/migrations` folder. Each folder there represents one migration that follows the migration
112
163
API.
@@ -122,7 +173,7 @@ Each migration must follow this API. It must export an object in its `index.js`
122
173
*`migrate` (function) - Function that performs the migration (see signature of this function below)
123
174
*`revert` (function) - If defined then this function will revert the migration to the previous version. Otherwise it is assumed that it is not possible to revert this migration.
124
175
125
-
##### `migrate(repoPath, isBrowser)`
176
+
####`.migrate(repoPath, isBrowser)`
126
177
127
178
_Do not confuse this function with the `require('ipfs-repo-migrations').migrate()` function that drives the whole migration process!_
128
179
@@ -131,7 +182,7 @@ Arguments:
131
182
*`options` (object, optional) - object containing `IPFSRepo` options, that should be used to construct a datastore instance.
132
183
*`isBrowser` (bool) - indicates if the migration is run in a browser environment (as opposed to NodeJS)
133
184
134
-
##### `revert(repoPath, isBrowser)`
185
+
####`.revert(repoPath, isBrowser)`
135
186
136
187
_Do not confuse this function with the `require('ipfs-repo-migrations').revert()` function that drives the whole backward migration process!_
137
188
@@ -140,7 +191,7 @@ Arguments:
140
191
*`options` (object, optional) - object containing `IPFSRepo` options, that should be used to construct the datastore instance.
141
192
*`isBrowser` (bool) - indicates if the migration is run in a browser environment (as opposed to NodeJS)
142
193
143
-
####Browser vs. NodeJS environments
194
+
### Browser vs. NodeJS environments
144
195
145
196
The migration might need to distinguish in which environment it runs (browser vs. NodeJS). For this reason there is an argument
146
197
`isBrowser` passed to migrations functions. But with simple migrations it should not be necessary to distinguish between
@@ -157,37 +208,23 @@ There are currently two main datastore implementations:
157
208
So with simple migrations you shouldn't worry about the difference between `datastore-fs` and `datastore-level`
158
209
and by default use the `datastore-fs` package (as the replace mechanism does not work vice versa).
159
210
160
-
####Guidelines
211
+
### Guidelines
161
212
162
213
The recommended way to write a new migration is to first bootstrap a dummy migration using the CLI:
163
214
164
215
```sh
165
-
>jsipfs-migrations add
216
+
>npm run new-migration
166
217
```
167
218
168
219
A new folder is created with the bootstrapped migration. You can then simply fill in the required fields and
169
220
write the rest of the migration!
170
221
171
-
#### Migration's dependencies
172
-
173
-
The size of the `js-ipfs` bundle is crucial for distribution in a browser environment, so dependency management of all related
174
-
packages is important.
175
-
176
-
If a migration needs to depend on some package, this dependency should be declared in the root's `package.json`. The author
177
-
of the migration should be thoughtful about adding dependencies that would significantly increase the size of the final bundle.
178
-
179
-
Most of the migration's dependencies will most likely overlap with `js-ipfs`'s dependencies and hence should not introduce
180
-
any significant overhead, but it is necessary to keep the versions of these dependencies in sync with `js-ipfs`. For this
181
-
reason migrations should be well tested to ensure correct behaviour over dependency updates.
182
-
An update of some dependency could introduce breaking change. In such a case the next steps should be discussed with a broader
183
-
audience.
184
-
185
-
#### Integration with js-ipfs
222
+
### Integration with js-ipfs
186
223
187
224
When a new migration is created, the repo version in [`js-ipfs-repo`](https://github.com/ipfs/js-ipfs-repo) should be updated with the new version,
188
225
together with updated version of this package. Then the updated version should be propagated to `js-ipfs`.
189
226
190
-
####Tests
227
+
### Tests
191
228
192
229
If a migration affects any of the following functionality, it must provide tests for the following functions
193
230
to work under the version of the repo that it migrates to:
@@ -199,15 +236,15 @@ If a migration affects any of the following functionality, it must provide tests
199
236
Every migration must have test coverage. Tests for migrations should be placed in the `/test/migrations/` folder. Most probably
200
237
you will have to plug the tests into `browser.js`/`node.js` if they require specific bootstrapping on each platform.
201
238
202
-
####Empty migrations
239
+
### Empty migrations
203
240
204
241
For interop with go-ipfs it might be necessary just to bump a version of a repo without any actual
205
242
modification as there might not be any changes needed in the JS implementation. For that purpose you can create an "empty migration".
206
243
207
244
The easiest way to do so is with the CLI:
208
245
209
246
```sh
210
-
>jsipfs-migrations add --empty
247
+
>npm run new-migration -- --empty
211
248
```
212
249
213
250
This will create an empty migration with the next version.
@@ -218,62 +255,9 @@ This will create an empty migration with the next version.
Executes a forward migration to a specific version, or to the latest version if a specific version is not specified.
227
-
228
-
**Arguments:**
229
-
230
-
*`path` (string, mandatory) - path to the repo to be migrated
231
-
*`options` (object, optional) - options for the migration
232
-
*`options.toVersion` (int, optional) - version to which the repo should be migrated. Defaults to the latest migration version.
233
-
*`options.ignoreLock` (bool, optional) - if true will not lock the repo when applying migrations. Use with caution.
234
-
*`options.repoOptions` (object, optional) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
235
-
*`options.onProgress` (function, optional) - callback that is called after finishing execution of each migration to report progress.
236
-
*`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.
*`migration` (object) - object of migration that just successfully finished running. See [Architecture of migrations](#architecture-of-migrations) for details.
244
-
*`counter` (int) - index of current migration.
245
-
*`totalMigrations` (int) - total count of migrations that will be run.
Executes backward migration to a specific version.
250
-
251
-
**Arguments:**
252
-
253
-
*`path` (string, mandatory) - path to the repo to be reverted
254
-
*`toVersion` (int, mandatory) - version to which the repo should be reverted to.
255
-
*`options` (object, optional) - options for the reversion
256
-
*`options.ignoreLock` (bool, optional) - if true will not lock the repo when applying migrations. Use with caution.
257
-
*`options.options` (object, optional) - options that are passed to migrations, that use them to construct the datastore. (options are the same as for IPFSRepo).
258
-
*`options.onProgress` (function, optional) - callback that is called after finishing execution of each migration to report progress.
259
-
*`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.
260
-
261
-
### `getLatestMigrationVersion() -> int`
262
-
263
-
Return the version of the latest migration.
264
-
265
-
## CLI
266
-
267
-
The CLI is a NodeJS binary named `jsipfs-repo-migrations`.
268
-
It has several commands:
269
-
270
-
*`migrate` - performs forward/backward migration to specific or latest version.
271
-
*`status` - check repo for migrations that should be run.
272
-
*`add` - bootstraps new migration.
273
-
274
-
For further details see the `--help` pages.
275
-
276
-
## Versioning
260
+
### Module versioning notes
277
261
278
262
In order to have good overview of what version of package contains what kind of migrations, this package follows this versioning schema: `0.<versionOfLastMigration>.<patches>`.
0 commit comments