Skip to content

fix: critical schema migration failure for existing databases (v0.3.1) - #430

Merged
ajianaz merged 1 commit into
developfrom
fix/schema-migration-index
Jun 21, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/schema-migration-index

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Critical Fix

Bug: DBs created with v0.2.x or earlier (schema ≤v7) failed to open after upgrading to v0.3.0. CREATE INDEX ... ON memories(slug) in the SCHEMA constant was executed BEFORE migrations added the slug column.

Impact: ALL existing users upgrading to v0.3.0 lose access to their data.

Fix: Split schema init into two phases:

  1. SCHEMA: CREATE TABLE + safe indexes
  2. SCHEMA_INDEXES: indexes on migration-added columns — run AFTER ensure_schema_version() completes

Index creation is best-effort (errors logged, not fatal).

Verified: Old DB (schema v7) now migrates v7→v8→v9→v10→v11 cleanly. Memory list, recall, edges, document create/list all work.

Version bump 0.3.0 → 0.3.1.

DBs created with v0.2.x or earlier (schema v7) failed to open after
upgrading to v0.3.0. CREATE INDEX ON memories(slug) in the SCHEMA
constant executed BEFORE migrations added the slug column.

Fix: split schema init into two phases. SCHEMA has CREATE TABLE only.
SCHEMA_INDEXES (on migration-added columns) runs AFTER migrations.
Best-effort index creation (errors logged, not fatal).

Version bump 0.3.0 -> 0.3.1.
self.ensure_schema_version()?;

// Create indexes on migration-added columns AFTER migrations complete.
// These are safe now — all columns exist regardless of original DB version.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (1)

  • crates/uteke-core/src/memory/schema.rs:72 — After self.ensure_schema_version()?, the new loop over SCHEMA_INDEXES swallows every execute_batch error and only logs at debug level: if let Err(e) = self.conn.execute_batch(stmt) { ... }. This means a database can finish opening even if a required index never gets created due to a real corruption or schema mismatch, causing degraded or inconsistent behavior that is much harder to detect than the previous fail-fast path for idx_memories_namespace and idx_memories_deprecated.

Review powered by cora-cli · BYOK · MIT

@ajianaz
ajianaz merged commit 6a8d970 into develop Jun 21, 2026
8 of 9 checks passed
@ajianaz
ajianaz deleted the fix/schema-migration-index branch June 21, 2026 22:59
ajianaz added a commit that referenced this pull request Aug 13, 2026
#430)

DBs created with v0.2.x or earlier (schema v7) failed to open after
upgrading to v0.3.0. CREATE INDEX ON memories(slug) in the SCHEMA
constant executed BEFORE migrations added the slug column.

Fix: split schema init into two phases. SCHEMA has CREATE TABLE only.
SCHEMA_INDEXES (on migration-added columns) runs AFTER migrations.
Best-effort index creation (errors logged, not fatal).

Version bump 0.3.0 -> 0.3.1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants