mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
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:
@@ -2,7 +2,7 @@
|
||||
|
||||
const assert = require('assert')
|
||||
const mapSeries = require('p-map-series')
|
||||
const fs = require('fs')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const rmrf = require('rimraf')
|
||||
const levelup = require('levelup')
|
||||
@@ -22,6 +22,8 @@ const {
|
||||
|
||||
const dbPath = './orbitdb/tests/create-open'
|
||||
const ipfsPath = './orbitdb/tests/create-open/ipfs'
|
||||
const migrationFixturePath = './test/fixtures/migration/cache-schema-test'
|
||||
const ipfsFixturesDir = './test/fixtures/ipfs'
|
||||
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Create & Open (${API})`, function() {
|
||||
@@ -36,6 +38,8 @@ Object.keys(testAPIs).forEach(API => {
|
||||
rmrf.sync(dbPath)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
await fs.copy(path.join(ipfsFixturesDir, 'blocks'), path.join(ipfsd.path, 'blocks'))
|
||||
await fs.copy(path.join(ipfsFixturesDir, 'datastore'), path.join(ipfsd.path, 'datastore'))
|
||||
orbitdb = await OrbitDB.createInstance(ipfs, { directory: dbPath })
|
||||
})
|
||||
|
||||
@@ -138,6 +142,37 @@ Object.keys(testAPIs).forEach(API => {
|
||||
assert.equal(fs.existsSync(dir), true)
|
||||
})
|
||||
|
||||
it('loads cache from previous version of orbit-db', async() => {
|
||||
const dbName = 'cache-schema-test'
|
||||
|
||||
db = await orbitdb.create(dbName, 'keyvalue')
|
||||
const manifestHash = db.address.root
|
||||
const migrationDataPath = path.join(dbPath, manifestHash, dbName)
|
||||
|
||||
await db.load()
|
||||
assert.equal((await db.get('key')), undefined)
|
||||
await db.close()
|
||||
await db.drop()
|
||||
|
||||
await fs.copy(migrationFixturePath, migrationDataPath)
|
||||
db = await orbitdb.create(dbName, 'keyvalue')
|
||||
await db.load()
|
||||
|
||||
assert.equal(manifestHash, db.address.root)
|
||||
assert.equal((await db.get('key')), 'value')
|
||||
})
|
||||
|
||||
it('loads cache from previous version of orbit-db with the directory option', async() => {
|
||||
const dbName = 'cache-schema-test2'
|
||||
const directory = path.join(dbPath, "some-other-place")
|
||||
|
||||
await fs.copy(migrationFixturePath, directory)
|
||||
db = await orbitdb.create(dbName, 'keyvalue', { directory })
|
||||
await db.load()
|
||||
|
||||
assert.equal((await db.get('key')), 'value')
|
||||
})
|
||||
|
||||
describe('Access Controller', function() {
|
||||
before(async () => {
|
||||
if (db) {
|
||||
|
||||
Reference in New Issue
Block a user