Tool to prune records from indexdb that do not exist in statedb
npm install @ocap/indexdb-pruneThis tool helps identify and remove records from Elasticsearch-based IndexDB that do not exist in the StateDB. The process is now streamlined with an API-based approach for better integration with other systems.
You can use the tool programmatically by importing it:
``javascript
const pruneIndexDB = require('@ocap/tools-indexdb-prune');
async function runPrune() {
try {
const deletedRecords = await pruneIndexDB();
console.log('Pruning completed successfully');
console.log('Deleted records:', deletedRecords);
// deletedRecords format: { account: ['id1', 'id2'], tx: ['txid1', 'txid2'] }
} catch (err) {
console.error('Pruning failed:', err);
}
}
runPrune();
`
The tool now performs these operations in a single flow:
1. Establishes connections to both IndexDB (Elasticsearch) and StateDB (Dolt)
2. Scans all tables in IndexDB (tx, account, asset, delegation, token, factory, stake, rollup, rollupBlock)
3. For each record, verifies if it exists in StateDB
4. Automatically deletes records that exist in IndexDB but not in StateDB
5. Returns a map of deleted record IDs by table
The function returns an object with tables as keys and arrays of deleted IDs as values:
`javascript``
{
account: ['accountId1', 'accountId2', ...],
tx: ['txId1', 'txId2', ...],
asset: ['assetId1', 'assetId2', ...],
// other tables...
}