LogoRobo.js

Integrity & Repair

Verify and repair database integrity, rebuild indexes, and recover catalogs.

Flashcore maintains derived structures (indexes, filters, unique constraints) alongside authoritative data (chunks, catalogs). Over time, these can drift due to crashes, bugs, or unexpected shutdowns. The integrity system detects and repairs these issues.

Checking Integrity

Verify a model's derived structures against its authoritative data:

import { Flashcore } from 'robo.js/flashcore'

const report = await Flashcore.$.checkIntegrity('Warning', {
	checkFilter: true,
	checkSortedIndexes: true,
	checkUniqueIndexes: true
})

console.log(report.isValid)
console.log(report.filter)          // { isValid, orphanedInFilter, missingInFilter }
console.log(report.sortedIndexes)   // Array of per-field results
console.log(report.uniqueIndex)     // { isValid, orphanedKeys, duplicates }
console.log(report.warnings)
console.log(report.durationMs)
import { Flashcore } from 'robo.js/flashcore'

const report = await Flashcore.$.checkIntegrity('Warning', {
	checkFilter: true,
	checkSortedIndexes: true,
	checkUniqueIndexes: true
})

console.log(report.isValid)
console.log(report.filter)          // { isValid, orphanedInFilter, missingInFilter }
console.log(report.sortedIndexes)   // Array of per-field results
console.log(report.uniqueIndex)     // { isValid, orphanedKeys, duplicates }
console.log(report.warnings)
console.log(report.durationMs)

Check Types

CheckWhat It Verifies
checkFilterCuckoo filter matches catalog entries
checkSortedIndexesSorted indexes match actual record values
checkUniqueIndexesUnique keys point to existing records, no duplicates

Progress Tracking

await Flashcore.$.checkIntegrity('Warning', {
	checkFilter: true,
	checkSortedIndexes: true,
	onProgress: (progress) => {
		console.log(`${progress.phase}: ${progress.checked}/${progress.total}`)
	}
})
await Flashcore.$.checkIntegrity('Warning', {
	checkFilter: true,
	checkSortedIndexes: true,
	onProgress: (progress) => {
		console.log(`${progress.phase}: ${progress.checked}/${progress.total}`)
	}
})

Repairing

Fix integrity issues detected by the checker:

const result = await Flashcore.$.repair('Warning')
// result.filter     — { success, repaired, unrepaired, warnings, durationMs }
// result.sortedIndexes — Map<field, RepairResult>
// result.uniqueIndex — RepairResult
const result = await Flashcore.$.repair('Warning')
// result.filter     — { success, repaired, unrepaired, warnings, durationMs }
// result.sortedIndexes — Map<field, RepairResult>
// result.uniqueIndex — RepairResult

Repair rebuilds derived structures from the authoritative chunk data. This is always safe — it does not modify your actual records.

Rebuilding Indexes

Rebuild all indexes for a model from scratch:

await Flashcore.$.rebuildIndexes('Warning')
await Flashcore.$.rebuildIndexes('Warning')

Catalog Rebuild

If the catalog itself is corrupted, rebuild it from chunk files:

import { rebuildCatalogFromChunks } from '@robojs/flashcore-extras/integrity'

await rebuildCatalogFromChunks(adapter, 'Warning')
// With explicit namespace:
// await rebuildCatalogFromChunks(adapter, 'Warning', 'my-namespace')
import { rebuildCatalogFromChunks } from '@robojs/flashcore-extras/integrity'

await rebuildCatalogFromChunks(adapter, 'Warning')
// With explicit namespace:
// await rebuildCatalogFromChunks(adapter, 'Warning', 'my-namespace')

CLI Commands

Manage integrity from the terminal:

CommandDescription
/db checkCheck integrity for all models
/db check --model WarningCheck a specific model
/db check --verboseShow detailed results
/db repairRepair all models
/db repair --model WarningRepair a specific model
/db repair --dry-runShow what would be repaired without making changes
/db rebuild-indexesRebuild all indexes

See CLI Commands for the full reference.

On this page