Skip to content

fix: remove duplicate document indexes from SCHEMA constant (#492) - #493

Merged
ajianaz merged 3 commits into
developfrom
fix/schema-migration-v12-index-order
Jun 29, 2026
Merged

ajianaz merged 3 commits into
developfrom
fix/schema-migration-v12-index-order

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #492 — v0.5.0 schema migration fails when upgrading from v0.4.x.

Root Cause

The v0.5.0 release added 4 hierarchical document indexes to the constant:

  • idx_documents_path
  • idx_documents_parent
  • idx_documents_depth
  • idx_documents_sort

These indexes reference columns added by migration v11→v12. However, SCHEMA is executed via execute_batch() before versioned migrations run. For existing v0.4.x DBs:

  1. CREATE TABLE IF NOT EXISTS documents → skipped (table already exists)
  2. CREATE INDEX IF NOT EXISTS idx_documents_path ON documents(path) → FAILS (column path doesn't exist)
  3. execute_batch is atomic → entire init_schema() fails

The indexes already exist in migrate_v11_to_v12() with proper column_exists guards, so they were duplicated.

Changes

File Change
store.rs Remove 4 duplicate indexes from SCHEMA constant
store.rs Add Store::from_conn() test helper
store.rs Add regression test simulating v0.4.x → v0.5.0 upgrade

Regression Test

test_migration_v11_to_v12_from_v04x_db:

  • Creates in-memory DB with v0.4.x schema (no hierarchy columns)
  • Sets schema_version to 11
  • Calls Store::from_conn() to trigger init + migration
  • Asserts: schema_version=12, all hierarchy columns exist, all indexes created

Test Limitation

Local test environment lacks libssl-dev (needed by ort build-deps), so tests verified on CI only.

Root cause: v0.5.0 added hierarchical document indexes
(idx_documents_path/parent/depth/sort) to the SCHEMA constant,
which runs via execute_batch() BEFORE versioned migrations. For DBs
upgrading from v0.4.x, the documents table already exists (skipped
by IF NOT EXISTS) but lacks the hierarchy columns, so CREATE INDEX
references non-existent columns and the entire init_schema() fails.

The indexes already exist in migrate_v11_to_v12() with proper
column-existence guards. Removing them from SCHEMA eliminates the
duplication and ordering conflict.

Also adds:
- Store::from_conn() test helper for pre-seeded DB migration tests
- Regression test: simulates v0.4.x DB (schema_version=11, documents
  table without hierarchy columns) and verifies migration v11→v12
  succeeds with all columns and indexes present
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-cli · BYOK · MIT

@ajianaz
ajianaz merged commit 1d7d894 into develop Jun 29, 2026
8 checks passed
@ajianaz
ajianaz deleted the fix/schema-migration-v12-index-order branch July 9, 2026 14:27
ajianaz added a commit that referenced this pull request Aug 13, 2026
…ex-order

fix: remove duplicate document indexes from SCHEMA constant (#492)
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.

v0.5.0 schema migration fails upgrading from v0.4.x — no such column: path (migration order bug)

1 participant