Preliminary cache migration code

cache loading test

this.attemptMigration

Migration data and cleanup

Linting

IPFS data

Revert "Linting"

This reverts commit e41bc4a9ec2011716300134f985c7ec749743177.

Revert "IPFS data"

This reverts commit 299e0b7b72d74cdbaec80ad0796211790404e4c3.

Better fixtures

package-lock.json

Test for directory options

directory option working

Fixing eventlog tests

Safer migration

Moving to migrations folder

Linting
This commit is contained in:
Mark Henderson
2019-08-31 23:01:17 -04:00
parent 9b58f429cd
commit e793edf9cf
42 changed files with 532 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ const exchangeHeads = require('./exchange-heads')
const { isDefined, io } = require('./utils')
const Storage = require('orbit-db-storage-adapter')
const leveldown = require('leveldown')
const migrations = require('./migrations')
const Logger = require('logplease')
const logger = Logger.create('orbit-db')
@@ -303,6 +304,8 @@ class OrbitDB {
if (haveDB && !options.overwrite) { throw new Error(`Database '${dbAddress}' already exists!`) }
await this._migrate(options, dbAddress)
// Save the database locally
await this._addManifestToCache(options.cache, dbAddress)
@@ -395,10 +398,21 @@ class OrbitDB {
if (!cache) {
return false
}
const data = await cache.get(path.join(dbAddress.toString(), '_manifest'))
const addr = dbAddress.toString()
const data = await cache.get(path.join(addr, '_manifest'))
return data !== undefined && data !== null
}
/**
* Runs all migrations inside the src/migration folder
* @param Object options Options to pass into the migration
* @param OrbitDBAddress dbAddress Address of database in OrbitDBAddress format
*/
async _migrate (options, dbAddress) {
await migrations.run(this, options, dbAddress)
}
/**
* Returns supported database types as an Array of strings
* Eg. [ 'counter', 'eventlog', 'feed', 'docstore', 'keyvalue']