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
| Check | What It Verifies |
|---|---|
checkFilter | Cuckoo filter matches catalog entries |
checkSortedIndexes | Sorted indexes match actual record values |
checkUniqueIndexes | Unique 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 — RepairResultconst result = await Flashcore.$.repair('Warning')
// result.filter — { success, repaired, unrepaired, warnings, durationMs }
// result.sortedIndexes — Map<field, RepairResult>
// result.uniqueIndex — RepairResultRepair 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:
| Command | Description |
|---|---|
/db check | Check integrity for all models |
/db check --model Warning | Check a specific model |
/db check --verbose | Show detailed results |
/db repair | Repair all models |
/db repair --model Warning | Repair a specific model |
/db repair --dry-run | Show what would be repaired without making changes |
/db rebuild-indexes | Rebuild all indexes |
See CLI Commands for the full reference.
