Skip to content

Commit

Permalink
Merge PR #1097 from 'theanmolsharma/followup'
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Nov 1, 2022
2 parents 0172a29 + 1f296d6 commit a44a7de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
39 changes: 26 additions & 13 deletions migrate/indexerdb0to1.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ async function updateChainVersion(db, version) {
await parent.write();
}

async function updateChainDB(chain) {
const chainDB = bdb.create({
location: chain,
compression: true,
cacheSize: 32 << 20,
createIfMissing: false
});

await chainDB.open();
console.log('Opened %s.', chain);

const chainVersion = await getVersion(chainDB);
if (chainVersion === 6) {
await updateChainVersion(chainDB, 7);
}
await chainDB.close();
}

async function checkVersion(db, version) {
console.log('Checking version.');

Expand Down Expand Up @@ -201,21 +219,16 @@ let count = 0;

// Updating chainDB version to ensure
// filter indexes are not duplicated.
const chainDB = bdb.create({
location: path.resolve(process.argv[2], '../chain'),
compression: true,
cacheSize: 32 << 20,
createIfMissing: false
});

console.log('Opened %s.', path.resolve(process.argv[2], '../chain'));
await chainDB.open();
const chain = path.resolve(process.argv[2], '../chain');
if (await fs.exists(chain)) {
await updateChainDB(chain);
}

const chainVersion = await getVersion(chainDB);
if (chainVersion === 6) {
await updateChainVersion(chainDB, 7);
// update spvChainDB if it exists
const spvchain = path.resolve(process.argv[2], '../spvchain');
if (await fs.exists(spvchain)) {
await updateChainDB(spvchain);
}
await chainDB.close();
})().then(() => {
console.log('Migrated %d databases.', count);
process.exit(0);
Expand Down
3 changes: 1 addition & 2 deletions migrate/latest
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ const wallet = resolve(prefix, 'wallet');
if (await fs.exists(spvchain))
exec(node, resolve(__dirname, 'chaindb4to6.js'), spvchain);

if (await fs.exists(index))
exec(node, resolve(__dirname, 'indexerdb0to1.js'), index);
exec(node, resolve(__dirname, 'indexerdb0to1.js'), index);

if (await fs.exists(wallet))
exec(node, resolve(__dirname, 'walletdb7to8.js'), wallet);
Expand Down

0 comments on commit a44a7de

Please sign in to comment.