Repository navigation
fix(db): use structural recovery schema check - #1487
Conversation
Use getSchemaDefinitions in getRecoverySchemaReference and checkHealthyDatabaseFile so upgraded databases and applySafeFixes-healed databases pass health checks during interrupted replacement journal recovery, and reuse getRecoverySchemaReference(currentVersion) in validateDirectBackup. Fixes #1483.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoUse structural schema checks for database recovery
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo
1.
|
Intent
Fixes #1483 (
https://github.com/FreeOpenSourcePOS/FloCafe/issues/1483): Inmain/db.ts:1804-1831, 1882-1914,checkHealthyDatabaseFile/isHealthyDatabaseFilecompares rawsqlite_master.sqltable definitions (normalizedSchemaDefinitions) against a freshly built reference instead of structural table definitions (getSchemaDefinitionsatmain/db.ts:4896-4914). Databases created on older versions and upgraded since (or healed byapplySafeFixes) have different rawCREATE TABLEtext and failcheckHealthyDatabaseFileduring interrupted replacement journal recovery (recoverInterruptedDatabaseReplacement). UpdategetRecoverySchemaReference/checkHealthyDatabaseFileto use structural table definitions (getSchemaDefinitions), reusegetRecoverySchemaReference(currentVersion)invalidateDirectBackup, and add regression tests covering upgraded databases.What Changed
getRecoverySchemaReferenceandcheckHealthyDatabaseFileinmain/db.tsto validate schema definitions viagetSchemaDefinitionsrather than rawsqlite_master.sqltext, and extendeddescribeTableStructureto record per-column/constraint collations andON CONFLICTresolution policies.getRecoverySchemaReference(currentVersion)insidevalidateDirectBackupso same-version direct backup validation shares the cached recovery schema reference, and updateddocs/architecture/data-and-migrations.mdto reflect the structural check and shared cache.tests/schema-health.test.tsandtests/schema-reference-cache.test.tsfor upgraded andapplySafeFixes-healed databases duringisHealthyDatabaseFileand interrupted replacement recovery,ON CONFLICTand collation drift detection, and cached reference reuse during direct restores.Risk Assessment
✅ Low: The change cleanly switches recovery schema validation to structural table definitions, reuses the cached recovery schema reference during direct backup validation, preserves per-column collation and conflict-policy checks, and adds thorough behavioral regression tests.
Testing
Ran the targeted schema health (
npm run test:schema-health, includingtests/schema-health.test.tsandtests/schema-reference-cache.test.ts) and backup/restore (npm run test:backup) test suites, compiled the backend (npm run build), and drove all three scenarios live against the real Electron/Express backend and SQLite engine in an isolated userData directory (saving the full verification report to~/.no-mistakes/evidence/01M6SMRZ2K8F6BCHM5TSVSNXAF/live-recovery-schema-validation.json); no UI surface was changed so no screenshot artifact was needed, and all scenarios and tests passed.Evidence: Live recovery schema validation report
{ "scenarios": { "scenario1_upgraded_journal_recovery": { "healthDriftFindingsBeforeFix": ["missing_column:products.cb_percent"], "applySafeFixesResponse": { "applied": ["missing_column:products.cb_percent"], "skipped": [], "errors": [] }, "healthCheckFindingsAfterFix": 0, "rawCreateTableSqlDiffersFromFreshInstall": true, "preparedPhaseRecovery": { "apiHealth": { "status": "ok", "db": "ok", "service": "Flo Local API" }, "recoveredCategory": { "id": "cat-upgraded-live", "name": "Upgraded Store Category" }, "journalRemoved": true }, "committedPhaseRecovery": { "apiHealth": { "status": "ok", "db": "ok", "service": "Flo Local API" }, "recoveredCategory": { "id": "cat-upgraded-live", "name": "Upgraded Store Category" }, "journalRemoved": true } }, "scenario2_direct_backup_restore_and_cache": { "coldRestoreHttp": { "status": 200, "body": { "success": true, "mode": "direct", "backupVersion": 124, "currentVersion": 124, "tablesRestored": 69, "cleanupPending": false } }, "coldRestoreSchemaBuildDelta": 1, "coldRestoreMemoryDbDelta": 1, "warmRestoreHttp": { "status": 200, "body": { "success": true, "mode": "direct", "backupVersion": 124, "currentVersion": 124, "tablesRestored": 69, "cleanupPending": false } }, "warmRestoreSchemaBuildDelta": 0, "warmRestoreMemoryDbDelta": 0, "transientCategoryRemovedByRestore": true }, "scenario3_adversarial_collation_and_conflict_guards": { "collationMovedOffPaymentMethodsName": { "isHealthyDatabaseFile": false, "startupJournalRecoveryRejectedWithError": "Interrupted database replacement recovery snapshot could not be validated" }, "columnUniqueOnConflictReplace": { "isHealthyDatabaseFile": false, "startupJournalRecoveryRejectedWithError": "Interrupted database replacement recovery snapshot could not be validated" }, "tableUniqueOnConflictReplace": { "isHealthyDatabaseFile": false, "startupJournalRecoveryRejectedWithError": "Interrupted database replacement recovery snapshot could not be validated" } } } }Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npm run test:schema-healthnpm run test:backupnpm run buildLive Electron + Express backend E2E verification driving/api/db-tools/health-check,/api/db-tools/apply-safe-fixes,/api/health,/api/db/restore,initDatabase(), andisHealthyDatabaseFile()across upgraded, healed, and adversarially tampered SQLite databases✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.