Repository navigation
fix(backup): include all 7 missing tables in backup/restore - #1903
Merged
Merged
Conversation
BACKUP_TABLES listed only 8 of the 15 live PostgreSQL tables. The 7 missing tables (mental_models, directives, async_operations, webhooks, file_storage, audit_log, graph_maintenance_queue) were never backed up, and because restore runs TRUNCATE banks CASCADE, the FK-to-banks children (mental_models, directives, async_operations, webhooks) were actively wiped on restore even though they were never saved. Add the missing tables in FK-dependency order, plus a guard test (test_backup_tables_covers_entire_schema) that introspects the live schema and fails if BACKUP_TABLES drifts from it. Extend the roundtrip test with a directive (FK->banks) to cover the cascade-wipe regression. Document the rule in the code-review skill so new tables don't silently escape the backup list.
nicoloboschi
pushed a commit
that referenced
this pull request
Jun 5, 2026
#1903 expanded BACKUP_TABLES to all 15 tables (the 7 previously-missing ones that could be silently dropped on restore), but the "backup includes" list still reflected the old ~8-table coverage. Update it to match: mental models, directives, webhooks, file storage, plus internal operational tables for a faithful full-database snapshot. Oracle-only observation_sources stays excluded (PostgreSQL-only backup). Regenerated skills/hindsight-docs mirror.
cdbartholomew
added a commit
that referenced
this pull request
Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
BACKUP_TABLESinhindsight-api-slim/hindsight_api/admin/cli.pylisted only 8 tables, but the live PostgreSQL schema has 15 (verified by building the schema on embedded pg0 and introspectinginformation_schema).7 tables were never backed up:
mental_models,directives,async_operations,webhooks,file_storage,audit_log,graph_maintenance_queue.This was worse than missing data. Restore runs
TRUNCATE banks CASCADE, andmental_models,directives,async_operations,webhooksall have a FK tobanks— so restore was actively wiping those tables (including core user data like mental models and directives) and never refilling them.Fix
admin/cli.py— add the 7 missing tables toBACKUP_TABLESin FK-dependency order (verified against the live schema's actual foreign keys), with a comment explaining the completeness requirement.tests/test_admin_backup_restore.pytest_backup_tables_covers_entire_schema— introspects the live schema and assertsBACKUP_TABLESequals the real table set (minusalembic_version). Fails CI if a future migration adds a table without updating the list.directivesrow (FK→banks) and asserts it survives restore, directly covering the cascade-wipe regression..claude/skills/code-review/SKILL.md— new review step + "must fix" bullet flagging any new PG table missing fromBACKUP_TABLES.Notes
observation_sourcesis intentionally excluded — it's Oracle-only (PG uses an array column); admin backup/restore is PG-only.async_operations,graph_maintenance_queue) andaudit_logare included so a backup is a faithful full snapshot. If we'd rather a restore not carry over another deployment's in-flight worker queue, these can move to an explicit documented exclusion set instead.Testing
All 6 tests in
test_admin_backup_restore.pypass; lint + format clean.