Skip to content

Commit 12b8ac8

Browse files
authored
fix: move migrations to published folder (#427)
In order to simplify the config, move the migrations into a folder that's already published to npm.
1 parent 2a32ae7 commit 12b8ac8

35 files changed

+50
-47
lines changed

packages/ipfs-repo-migrations/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ This framework:
6969
### Use in Node.js
7070

7171
```js
72-
const migrations from 'ipfs-repo-migrations')
72+
import migrations from 'ipfs-repo-migrations'
7373
```
7474

7575
### Use in a browser with browserify, webpack or any other bundler
7676

7777
```js
78-
const migrations from 'ipfs-repo-migrations')
78+
import migrations from 'ipfs-repo-migrations'
7979
```
8080

8181
## Usage
8282

8383
Example:
8484

8585
```js
86-
const migrations from 'ipfs-repo-migrations')
86+
import migrations from 'ipfs-repo-migrations'
8787

8888
const repoPath = 'some/repo/path'
8989
const currentRepoVersion = 7
@@ -161,10 +161,10 @@ be run again.
161161

162162
### Architecture of a migration
163163

164-
All migrations are placed in the `/migrations` folder. Each folder there represents one migration that follows the migration
164+
All migrations are placed in the `/src/migrations` folder. Each folder there represents one migration that follows the migration
165165
API.
166166

167-
All migrations are collected in `/migrations/index.js`, which should not be edited manually.
167+
All migrations are collected in `/src/migrations/index.js`, which should not be edited manually.
168168

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

packages/ipfs-repo-migrations/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@
5454
"extends": "ipfs",
5555
"parserOptions": {
5656
"sourceType": "module"
57-
}
57+
},
58+
"ignorePatterns": [
59+
"src/migrations/migration-9/pin.js",
60+
"src/migrations/migration-9/pin.d.ts",
61+
"src/migrations/migration-12/pb/*"
62+
]
5863
},
5964
"release": {
6065
"branches": [

packages/ipfs-repo-migrations/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint complexity: ["error", 28] */
22

3-
import defaultMigrations from '../migrations/index.js'
3+
import defaultMigrations from './migrations/index.js'
44
import * as repoVersion from './repo/version.js'
55
import * as Errors from './errors.js'
66
import { wrapBackends } from './utils.js'

packages/ipfs-repo-migrations/migrations/index.js renamed to packages/ipfs-repo-migrations/src/migrations/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { migration as migration11 } from './migration-11/index.js'
55
import { migration as migration12 } from './migration-12/index.js'
66

77
/**
8-
* @type {import('../src/types').Migration}
8+
* @type {import('../types').Migration}
99
*/
1010
const emptyMigration = {
1111
description: 'Empty migration.',

packages/ipfs-repo-migrations/migrations/migration-10/index.js renamed to packages/ipfs-repo-migrations/src/migrations/migration-10/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
import { findLevelJs } from '../../src/utils.js'
2+
import { findLevelJs } from '../../utils.js'
33
import { fromString } from 'uint8arrays/from-string'
44
import { toString } from 'uint8arrays/to-string'
55

66
/**
7-
* @typedef {import('../../src/types').Migration} Migration
7+
* @typedef {import('../../types').Migration} Migration
88
* @typedef {import('interface-datastore').Datastore} Datastore
99
* @typedef {import('interface-blockstore').Blockstore} Blockstore
10-
* @typedef {import('../../src/types').MigrationProgressCallback} MigrationProgressCallback
10+
* @typedef {import('../../types').MigrationProgressCallback} MigrationProgressCallback
1111
*
1212
* @typedef {{ type: 'del', key: string | Uint8Array } | { type: 'put', key: string | Uint8Array, value: Uint8Array }} Operation
1313
* @typedef {function (string, Uint8Array): Operation[]} UpgradeFunction
@@ -87,7 +87,7 @@ function unwrap (store) {
8787
}
8888

8989
/**
90-
* @param {import('../../src/types').Backends} backends
90+
* @param {import('../../types').Backends} backends
9191
* @param {MigrationProgressCallback} onProgress
9292
* @param {*} fn
9393
*/

packages/ipfs-repo-migrations/migrations/migration-11/index.js renamed to packages/ipfs-repo-migrations/src/migrations/migration-11/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Key } from 'interface-datastore/key'
44
const MFS_ROOT_KEY = new Key('/local/filesroot')
55

66
/**
7-
* @param {import('../../src/types').Backends} backends
8-
* @param {import('../../src/types').MigrationProgressCallback} onProgress
7+
* @param {import('../../types').Backends} backends
8+
* @param {import('../../types').MigrationProgressCallback} onProgress
99
*/
1010
async function storeMfsRootInDatastore (backends, onProgress = () => {}) {
1111
onProgress(100, 'Migrating MFS root to repo datastore')
@@ -26,8 +26,8 @@ async function storeMfsRootInDatastore (backends, onProgress = () => {}) {
2626
}
2727

2828
/**
29-
* @param {import('../../src/types').Backends} backends
30-
* @param {import('../../src/types').MigrationProgressCallback} onProgress
29+
* @param {import('../../types').Backends} backends
30+
* @param {import('../../types').MigrationProgressCallback} onProgress
3131
*/
3232
async function storeMfsRootInRoot (backends, onProgress = () => {}) {
3333
onProgress(100, 'Migrating MFS root to repo root datastore')
@@ -47,7 +47,7 @@ async function storeMfsRootInRoot (backends, onProgress = () => {}) {
4747
onProgress(100, 'Stored MFS root in repo root datastore')
4848
}
4949

50-
/** @type {import('../../src/types').Migration} */
50+
/** @type {import('../../types').Migration} */
5151
export const migration = {
5252
version: 11,
5353
description: 'Store mfs root in the datastore',

packages/ipfs-repo-migrations/migrations/migration-12/index.js renamed to packages/ipfs-repo-migrations/src/migrations/migration-12/index.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import $protobuf from "protobufjs/minimal.js"
2-
3-
// @ts-expect-error Explicitly disable long.js support
4-
$protobuf.util.Long = undefined
5-
$protobuf.configure()
6-
1+
import $protobuf from 'protobufjs/minimal.js'
72
import { Key } from 'interface-datastore/key'
83
import { Protocols } from './pb/proto-book.js'
94
import { Addresses } from './pb/address-book.js'
@@ -12,9 +7,13 @@ import { Envelope } from './pb/envelope.js'
127
import { PeerRecord } from './pb/peer-record.js'
138
import { multiaddr } from '@multiformats/multiaddr'
149

10+
// @ts-expect-error Explicitly disable long.js support
11+
$protobuf.util.Long = undefined
12+
$protobuf.configure()
13+
1514
/**
16-
* @param {import('../../src/types').Backends} backends
17-
* @param {import('../../src/types').MigrationProgressCallback} onProgress
15+
* @param {import('../../types').Backends} backends
16+
* @param {import('../../types').MigrationProgressCallback} onProgress
1817
*/
1918
async function storePeerUnderSingleDatastoreKey (backends, onProgress = () => {}) {
2019
onProgress(0, 'Storing each peerstore key under a single datastore key')
@@ -31,7 +30,7 @@ async function storePeerUnderSingleDatastoreKey (backends, onProgress = () => {}
3130
})) {
3231
keys.push(key)
3332
const keyStr = key.toString()
34-
const [_, prefix, type, peerId, metadataKey] = keyStr.split('/')
33+
const [, prefix, type, peerId, metadataKey] = keyStr.split('/')
3534

3635
if (prefix !== 'peers') {
3736
continue
@@ -95,8 +94,8 @@ async function storePeerUnderSingleDatastoreKey (backends, onProgress = () => {}
9594
}
9695

9796
/**
98-
* @param {import('../../src/types').Backends} backends
99-
* @param {import('../../src/types').MigrationProgressCallback} onProgress
97+
* @param {import('../../types').Backends} backends
98+
* @param {import('../../types').MigrationProgressCallback} onProgress
10099
*/
101100
async function storePeerUnderMultipleDatastoreKeys (backends, onProgress = () => {}) {
102101
onProgress(0, 'Storing each peerstore key under a multiple datastore keys')
@@ -114,7 +113,7 @@ async function storePeerUnderMultipleDatastoreKeys (backends, onProgress = () =>
114113
keys.push(key)
115114
const keyStr = key.toString()
116115

117-
const [_, _prefix, peerId] = keyStr.split('/')
116+
const [, , peerId] = keyStr.split('/')
118117

119118
peers[peerId] = Peer.decode(value)
120119
}
@@ -170,7 +169,7 @@ async function storePeerUnderMultipleDatastoreKeys (backends, onProgress = () =>
170169
onProgress(100, 'Stored each peerstore key under multiple datastore keys')
171170
}
172171

173-
/** @type {import('../../src/types').Migration} */
172+
/** @type {import('../../types').Migration} */
174173
export const migration = {
175174
version: 12,
176175
description: 'Store each peerstore peer under a single datastore key',

0 commit comments

Comments
 (0)