Repository navigation
fix: harden schema migrations for partially-migrated databases - #435
Merged
Merged
Conversation
Three fixes for edge cases encountered during v0.2.0 → v0.3.1 upgrade: 1. migrate_v9_to_v10: add column_exists guards for source/source_type - Fresh v0.3.0 DBs already have these columns via SCHEMA constant - Running migration on such DBs crashed with 'duplicate column name' 2. migrate_v7_to_v8: make idx_memories_slug best-effort - Separated from memory_edges batch to prevent fatal error - Log at debug level if index creation fails (defensive) 3. SCHEMA source_type default: 'user' → 'unknown' - Consistent with migrate_v9_to_v10 default - Fresh DBs and migrated DBs now use the same source_type default
🔍 Cora AI Code Review❌ Blocked — critical issues found. 🔴 Error (2)
Review powered by cora-cli · BYOK · MIT |
CodeCora flagged that making idx_memories_slug best-effort could leave databases without the index while reporting migration success. Revert to hard error but separate from the memory_edges batch for clearer error messages (separate error context: 'slug index' vs 'memory_edges'). The original production bug was in SCHEMA_INDEXES ordering (fixed in develop), not in this migration itself.
| .map_err(|e| Error::db("schema migration v9 to v10", e))?; | ||
| // Guard with column_exists to handle partially-migrated databases | ||
| // (e.g. fresh v0.3.0 DBs that already have these columns via SCHEMA). | ||
| if !self.column_exists("source") { |
CodeCora flagged that changing the default affects existing databases inconsistently — SQLite doesn't support ALTER DEFAULT, so old DBs keep 'user' while new DBs would get 'unknown'. The intentional difference is documented: - SCHEMA DEFAULT 'user' — fresh DBs, code always sets source_type explicitly - Migration DEFAULT 'unknown' — legacy rows without provenance info This is the original behavior, now with column_exists guards as the real fix for partially-migrated databases.
| .map_err(|e| Error::db("schema migration v7 to v8", e))?; | ||
|
|
||
| // Slug index — hard failure since slug column was just added above. | ||
| // If this somehow fails, the migration must not proceed (slug lookups |
ajianaz
added a commit
that referenced
this pull request
Jun 22, 2026
- Bump version 0.3.1 → 0.3.2 across all crates - Add CHANGELOG entry for #435 (migration hardening) and #434 (docs checklist) - Update AGENT.md version + schema version (v7 → v11) - Update README badge + CLI reference version Co-authored-by: ajianaz <[email protected]>
ajianaz
added a commit
that referenced
this pull request
Jun 22, 2026
* docs: add detailed documentation checklist to AGENT.md release process (#434) Release checklist now explicitly lists ALL docs that must be updated before tagging: README, CHANGELOG, cli-reference, configuration, architecture, roadmap, hermes integration. No exceptions. Also updated version to 0.3.1 and test count to 295. * fix: harden schema migrations for partially-migrated databases (#435) * fix: harden schema migrations for partially-migrated databases Three fixes for edge cases encountered during v0.2.0 → v0.3.1 upgrade: 1. migrate_v9_to_v10: add column_exists guards for source/source_type - Fresh v0.3.0 DBs already have these columns via SCHEMA constant - Running migration on such DBs crashed with 'duplicate column name' 2. migrate_v7_to_v8: make idx_memories_slug best-effort - Separated from memory_edges batch to prevent fatal error - Log at debug level if index creation fails (defensive) 3. SCHEMA source_type default: 'user' → 'unknown' - Consistent with migrate_v9_to_v10 default - Fresh DBs and migrated DBs now use the same source_type default * refactor: keep slug index as hard error, separate from batch CodeCora flagged that making idx_memories_slug best-effort could leave databases without the index while reporting migration success. Revert to hard error but separate from the memory_edges batch for clearer error messages (separate error context: 'slug index' vs 'memory_edges'). The original production bug was in SCHEMA_INDEXES ordering (fixed in develop), not in this migration itself. * revert: restore source_type DEFAULT 'user' in SCHEMA CodeCora flagged that changing the default affects existing databases inconsistently — SQLite doesn't support ALTER DEFAULT, so old DBs keep 'user' while new DBs would get 'unknown'. The intentional difference is documented: - SCHEMA DEFAULT 'user' — fresh DBs, code always sets source_type explicitly - Migration DEFAULT 'unknown' — legacy rows without provenance info This is the original behavior, now with column_exists guards as the real fix for partially-migrated databases. --------- Co-authored-by: ajianaz <[email protected]> * release: v0.3.2 — schema migration hardening (#436) - Bump version 0.3.1 → 0.3.2 across all crates - Add CHANGELOG entry for #435 (migration hardening) and #434 (docs checklist) - Update AGENT.md version + schema version (v7 → v11) - Update README badge + CLI reference version Co-authored-by: ajianaz <[email protected]> --------- Co-authored-by: ajianaz <[email protected]>
ajianaz
added a commit
that referenced
this pull request
Aug 13, 2026
* fix: harden schema migrations for partially-migrated databases Three fixes for edge cases encountered during v0.2.0 → v0.3.1 upgrade: 1. migrate_v9_to_v10: add column_exists guards for source/source_type - Fresh v0.3.0 DBs already have these columns via SCHEMA constant - Running migration on such DBs crashed with 'duplicate column name' 2. migrate_v7_to_v8: make idx_memories_slug best-effort - Separated from memory_edges batch to prevent fatal error - Log at debug level if index creation fails (defensive) 3. SCHEMA source_type default: 'user' → 'unknown' - Consistent with migrate_v9_to_v10 default - Fresh DBs and migrated DBs now use the same source_type default * refactor: keep slug index as hard error, separate from batch CodeCora flagged that making idx_memories_slug best-effort could leave databases without the index while reporting migration success. Revert to hard error but separate from the memory_edges batch for clearer error messages (separate error context: 'slug index' vs 'memory_edges'). The original production bug was in SCHEMA_INDEXES ordering (fixed in develop), not in this migration itself. * revert: restore source_type DEFAULT 'user' in SCHEMA CodeCora flagged that changing the default affects existing databases inconsistently — SQLite doesn't support ALTER DEFAULT, so old DBs keep 'user' while new DBs would get 'unknown'. The intentional difference is documented: - SCHEMA DEFAULT 'user' — fresh DBs, code always sets source_type explicitly - Migration DEFAULT 'unknown' — legacy rows without provenance info This is the original behavior, now with column_exists guards as the real fix for partially-migrated databases. --------- Co-authored-by: ajianaz <[email protected]>
ajianaz
added a commit
that referenced
this pull request
Aug 13, 2026
- Bump version 0.3.1 → 0.3.2 across all crates - Add CHANGELOG entry for #435 (migration hardening) and #434 (docs checklist) - Update AGENT.md version + schema version (v7 → v11) - Update README badge + CLI reference version Co-authored-by: ajianaz <[email protected]>
ajianaz
added a commit
that referenced
this pull request
Aug 13, 2026
* docs: add detailed documentation checklist to AGENT.md release process (#434) Release checklist now explicitly lists ALL docs that must be updated before tagging: README, CHANGELOG, cli-reference, configuration, architecture, roadmap, hermes integration. No exceptions. Also updated version to 0.3.1 and test count to 295. * fix: harden schema migrations for partially-migrated databases (#435) * fix: harden schema migrations for partially-migrated databases Three fixes for edge cases encountered during v0.2.0 → v0.3.1 upgrade: 1. migrate_v9_to_v10: add column_exists guards for source/source_type - Fresh v0.3.0 DBs already have these columns via SCHEMA constant - Running migration on such DBs crashed with 'duplicate column name' 2. migrate_v7_to_v8: make idx_memories_slug best-effort - Separated from memory_edges batch to prevent fatal error - Log at debug level if index creation fails (defensive) 3. SCHEMA source_type default: 'user' → 'unknown' - Consistent with migrate_v9_to_v10 default - Fresh DBs and migrated DBs now use the same source_type default * refactor: keep slug index as hard error, separate from batch CodeCora flagged that making idx_memories_slug best-effort could leave databases without the index while reporting migration success. Revert to hard error but separate from the memory_edges batch for clearer error messages (separate error context: 'slug index' vs 'memory_edges'). The original production bug was in SCHEMA_INDEXES ordering (fixed in develop), not in this migration itself. * revert: restore source_type DEFAULT 'user' in SCHEMA CodeCora flagged that changing the default affects existing databases inconsistently — SQLite doesn't support ALTER DEFAULT, so old DBs keep 'user' while new DBs would get 'unknown'. The intentional difference is documented: - SCHEMA DEFAULT 'user' — fresh DBs, code always sets source_type explicitly - Migration DEFAULT 'unknown' — legacy rows without provenance info This is the original behavior, now with column_exists guards as the real fix for partially-migrated databases. --------- Co-authored-by: ajianaz <[email protected]> * release: v0.3.2 — schema migration hardening (#436) - Bump version 0.3.1 → 0.3.2 across all crates - Add CHANGELOG entry for #435 (migration hardening) and #434 (docs checklist) - Update AGENT.md version + schema version (v7 → v11) - Update README badge + CLI reference version Co-authored-by: ajianaz <[email protected]> --------- Co-authored-by: ajianaz <[email protected]>
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.
Summary
Fixes a crash during v0.2.0 → v0.3.1 upgrade where
migrate_v9_to_v10fails withduplicate column nameon fresh v0.3.0 databases that already havesourceandsource_typecolumns via the SCHEMA constant.Changes
1.
migrate_v9_to_v10— Addcolumn_existsguardssourceandsource_typecolumns via SCHEMAduplicate column namecolumn_exists(), consistent with v3→v4 patterncolumn_exists()is table-scoped (SELECT * FROM memories LIMIT 0) so no cross-table collision risk2.
migrate_v7_to_v8— Extract slug index into separate statementrun_migrations()→unchecked_transaction)CodeCora Alerts — False Positives
Both CodeCora alerts are false positives due to context the SARIF analysis cannot see:
L405 'partially migrated state': The slug index IS inside a transaction —
run_migrations()wraps each step inunchecked_transaction()(schema.rs L146-185). CodeCora only sees the diff, not the call site.L500 'column_exists not table-scoped':
column_exists()queriesSELECT * FROM memories LIMIT 0— it IS table-scoped (schema.rs L330-334). CodeCora assumes it searches globally.Testing
Related