Skip to content

Commit

Permalink
fix: move migrations to published folder (#427)
Browse files Browse the repository at this point in the history
In order to simplify the config, move the migrations into a folder that's already published to npm.
  • Loading branch information
achingbrain authored Oct 19, 2022
1 parent 2a32ae7 commit 12b8ac8
Show file tree
Hide file tree
Showing 35 changed files with 50 additions and 47 deletions.
10 changes: 5 additions & 5 deletions packages/ipfs-repo-migrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ This framework:
### Use in Node.js

```js
const migrations from 'ipfs-repo-migrations')
import migrations from 'ipfs-repo-migrations'
```

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

```js
const migrations from 'ipfs-repo-migrations')
import migrations from 'ipfs-repo-migrations'
```

## Usage

Example:

```js
const migrations from 'ipfs-repo-migrations')
import migrations from 'ipfs-repo-migrations'

const repoPath = 'some/repo/path'
const currentRepoVersion = 7
Expand Down Expand Up @@ -161,10 +161,10 @@ be run again.

### Architecture of a migration

All migrations are placed in the `/migrations` folder. Each folder there represents one migration that follows the migration
All migrations are placed in the `/src/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.
All migrations are collected in `/src/migrations/index.js`, which should not be edited manually.

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

Expand Down
7 changes: 6 additions & 1 deletion packages/ipfs-repo-migrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@
"extends": "ipfs",
"parserOptions": {
"sourceType": "module"
}
},
"ignorePatterns": [
"src/migrations/migration-9/pin.js",
"src/migrations/migration-9/pin.d.ts",
"src/migrations/migration-12/pb/*"
]
},
"release": {
"branches": [
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-repo-migrations/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint complexity: ["error", 28] */

import defaultMigrations from '../migrations/index.js'
import defaultMigrations from './migrations/index.js'
import * as repoVersion from './repo/version.js'
import * as Errors from './errors.js'
import { wrapBackends } from './utils.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { migration as migration11 } from './migration-11/index.js'
import { migration as migration12 } from './migration-12/index.js'

/**
* @type {import('../src/types').Migration}
* @type {import('../types').Migration}
*/
const emptyMigration = {
description: 'Empty migration.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

import { findLevelJs } from '../../src/utils.js'
import { findLevelJs } from '../../utils.js'
import { fromString } from 'uint8arrays/from-string'
import { toString } from 'uint8arrays/to-string'

/**
* @typedef {import('../../src/types').Migration} Migration
* @typedef {import('../../types').Migration} Migration
* @typedef {import('interface-datastore').Datastore} Datastore
* @typedef {import('interface-blockstore').Blockstore} Blockstore
* @typedef {import('../../src/types').MigrationProgressCallback} MigrationProgressCallback
* @typedef {import('../../types').MigrationProgressCallback} MigrationProgressCallback
*
* @typedef {{ type: 'del', key: string | Uint8Array } | { type: 'put', key: string | Uint8Array, value: Uint8Array }} Operation
* @typedef {function (string, Uint8Array): Operation[]} UpgradeFunction
Expand Down Expand Up @@ -87,7 +87,7 @@ function unwrap (store) {
}

/**
* @param {import('../../src/types').Backends} backends
* @param {import('../../types').Backends} backends
* @param {MigrationProgressCallback} onProgress
* @param {*} fn
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Key } from 'interface-datastore/key'
const MFS_ROOT_KEY = new Key('/local/filesroot')

/**
* @param {import('../../src/types').Backends} backends
* @param {import('../../src/types').MigrationProgressCallback} onProgress
* @param {import('../../types').Backends} backends
* @param {import('../../types').MigrationProgressCallback} onProgress
*/
async function storeMfsRootInDatastore (backends, onProgress = () => {}) {
onProgress(100, 'Migrating MFS root to repo datastore')
Expand All @@ -26,8 +26,8 @@ async function storeMfsRootInDatastore (backends, onProgress = () => {}) {
}

/**
* @param {import('../../src/types').Backends} backends
* @param {import('../../src/types').MigrationProgressCallback} onProgress
* @param {import('../../types').Backends} backends
* @param {import('../../types').MigrationProgressCallback} onProgress
*/
async function storeMfsRootInRoot (backends, onProgress = () => {}) {
onProgress(100, 'Migrating MFS root to repo root datastore')
Expand All @@ -47,7 +47,7 @@ async function storeMfsRootInRoot (backends, onProgress = () => {}) {
onProgress(100, 'Stored MFS root in repo root datastore')
}

/** @type {import('../../src/types').Migration} */
/** @type {import('../../types').Migration} */
export const migration = {
version: 11,
description: 'Store mfs root in the datastore',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import $protobuf from "protobufjs/minimal.js"

// @ts-expect-error Explicitly disable long.js support
$protobuf.util.Long = undefined
$protobuf.configure()

import $protobuf from 'protobufjs/minimal.js'
import { Key } from 'interface-datastore/key'
import { Protocols } from './pb/proto-book.js'
import { Addresses } from './pb/address-book.js'
Expand All @@ -12,9 +7,13 @@ import { Envelope } from './pb/envelope.js'
import { PeerRecord } from './pb/peer-record.js'
import { multiaddr } from '@multiformats/multiaddr'

// @ts-expect-error Explicitly disable long.js support
$protobuf.util.Long = undefined
$protobuf.configure()

/**
* @param {import('../../src/types').Backends} backends
* @param {import('../../src/types').MigrationProgressCallback} onProgress
* @param {import('../../types').Backends} backends
* @param {import('../../types').MigrationProgressCallback} onProgress
*/
async function storePeerUnderSingleDatastoreKey (backends, onProgress = () => {}) {
onProgress(0, 'Storing each peerstore key under a single datastore key')
Expand All @@ -31,7 +30,7 @@ async function storePeerUnderSingleDatastoreKey (backends, onProgress = () => {}
})) {
keys.push(key)
const keyStr = key.toString()
const [_, prefix, type, peerId, metadataKey] = keyStr.split('/')
const [, prefix, type, peerId, metadataKey] = keyStr.split('/')

if (prefix !== 'peers') {
continue
Expand Down Expand Up @@ -95,8 +94,8 @@ async function storePeerUnderSingleDatastoreKey (backends, onProgress = () => {}
}

/**
* @param {import('../../src/types').Backends} backends
* @param {import('../../src/types').MigrationProgressCallback} onProgress
* @param {import('../../types').Backends} backends
* @param {import('../../types').MigrationProgressCallback} onProgress
*/
async function storePeerUnderMultipleDatastoreKeys (backends, onProgress = () => {}) {
onProgress(0, 'Storing each peerstore key under a multiple datastore keys')
Expand All @@ -114,7 +113,7 @@ async function storePeerUnderMultipleDatastoreKeys (backends, onProgress = () =>
keys.push(key)
const keyStr = key.toString()

const [_, _prefix, peerId] = keyStr.split('/')
const [, , peerId] = keyStr.split('/')

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

/** @type {import('../../src/types').Migration} */
/** @type {import('../../types').Migration} */
export const migration = {
version: 12,
description: 'Store each peerstore peer under a single datastore key',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as mhd from 'multiformats/hashes/digest'
const log = debug('ipfs:repo:migrator:migration-8')

/**
* @typedef {import('../../src/types').Migration} Migration
* @typedef {import('../../types').Migration} Migration
* @typedef {import('interface-datastore').Datastore} Datastore
*/

Expand Down Expand Up @@ -64,7 +64,7 @@ function keyToCid (key) {
}

/**
* @param {import('../../src/types').Backends} backends
* @param {import('../../types').Backends} backends
* @param {(percent: number, message: string) => void} onProgress
* @param {(key: Key) => Key} keyFunction
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import * as mhd from 'multiformats/hashes/digest'
import { base32 } from 'multiformats/bases/base32'

/**
* @typedef {import('../../src/types').Migration} Migration
* @typedef {import('../../src/types').MigrationProgressCallback} MigrationProgressCallback
* @typedef {import('../../types').Migration} Migration
* @typedef {import('../../types').MigrationProgressCallback} MigrationProgressCallback
* @typedef {import('interface-datastore').Datastore} Datastore
* @typedef {import('interface-blockstore').Blockstore} Blockstore
* @typedef {import('multiformats/cid').Version} CIDVersion
Expand Down Expand Up @@ -129,7 +129,7 @@ async function pinsToDAG (blockstore, datastore, pinstore, onProgress) {
}

/**
* @param {import('../../src/types').Backends} backends
* @param {import('../../types').Backends} backends
* @param {MigrationProgressCallback} onProgress
* @param {*} fn
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export const PinTypes = {
/**
* @param {import('multiformats').CID} cid
*/
export function cidToKey (cid) {
export function cidToKey (cid) {
return new Key(`/${base32.encode(cid.multihash.bytes).toUpperCase().substring(1)}`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { expect } from 'aegir/chai'
import { CID } from 'multiformats/cid'
import { BaseBlockstore } from 'blockstore-core/base'
import { migration } from '../../migrations/migration-10/index.js'
import { migration } from '../../src/migrations/migration-10/index.js'
import { Key } from 'interface-datastore/key'
import { fromString } from 'uint8arrays/from-string'
import { equals } from 'uint8arrays/equals'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { expect } from 'aegir/chai'
import { CID } from 'multiformats/cid'
import { migration } from '../../migrations/migration-11/index.js'
import { migration } from '../../src/migrations/migration-11/index.js'
import { Key } from 'interface-datastore/key'

const MFS_ROOT_KEY = new Key('/local/filesroot')
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { expect } from 'aegir/chai'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { migration } from '../../migrations/migration-8/index.js'
import { migration } from '../../src/migrations/migration-8/index.js'
import { Key } from 'interface-datastore/key'

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { expect } from 'aegir/chai'
import * as cbor from 'cborg'
import { migration } from '../../migrations/migration-9/index.js'
import { PIN_DS_KEY } from '../../migrations/migration-9/utils.js'
import { migration } from '../../src/migrations/migration-9/index.js'
import { PIN_DS_KEY } from '../../src/migrations/migration-9/utils.js'
import { CID } from 'multiformats/cid'
import { CarReader } from '@ipld/car'
import loadFixture from 'aegir/fixtures'
Expand Down
9 changes: 4 additions & 5 deletions packages/ipfs-repo-migrations/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
},
"include": [
"src",
"test",
"migrations"
"test"
],
"exclude": [
"migrations/migration-9/pin.js",
"migrations/migration-9/pin.d.ts",
"migrations/migration-12/pb"
"src/migrations/migration-9/pin.js",
"src/migrations/migration-9/pin.d.ts",
"src/migrations/migration-12/pb"
]
}

0 comments on commit 12b8ac8

Please sign in to comment.