Skip to content

🐛 Schema migration v11→v12 fails to add has_children column #500

Closed

Description

@ajianaz

Issue 2: Schema Migration v11 to v12 fails to add has_children column

Problem

The migrate_v11_to_v12() migration marks schema version 12 and creates indexes, but fails to add the has_children column to the documents table. This breaks ALL document operations (create/get/list) with:

Error: no such column: has_children in SELECT ... FROM documents

Reproduction

On a database that was created before v0.4.0 and upgraded through multiple versions:

uteke doc create test --content "hello"
# Error: Failed to create document: get document by slug: database operation failed

Root Cause

The DB schema_version is already 12 but the has_children column is missing. The column_exists_in() guard in the migration returns false (column doesn't exist), but the ALTER TABLE somehow didn't execute or was rolled back silently while the version was still bumped.

Likely cause: An intermediate binary (v0.4.x dev) ran a partial migration that added some columns and set version 12, but missed has_children. Subsequent migrations are skipped because version is already 12.

Impact

  • All uteke doc commands fail
  • All /doc/* HTTP endpoints return 500
  • uteke repair does NOT fix this (only rebuilds vector index)

Expected

  • uteke repair should detect and fix missing columns
  • Migration should be idempotent and complete

Workaround

ALTER TABLE documents ADD COLUMN has_children INTEGER NOT NULL DEFAULT 0;

Severity

High — breaks document features on upgraded databases.

Activity

  1. added
    bug
    scope:core
    on Jun 30, 2026
  2. ajianaz commented on Jun 30, 2026

    @ajianaz
    CollaboratorAuthor

    Root cause analysis

    Confirmed: schema_version is 12 but has_children column is missing.

    sqlite3 .tables → documents exists
    PRAGMA table_info(documents) → 15 columns, has_children NOT among them
    SELECT version FROM schema_version → (12,) exists
    idx_documents_path/parent/depth/sort → all exist (created by migration)
    documents_fts → does NOT exist (also from migration v11→v12)
    

    The migration ran partially: indexes created, but column addition and FTS creation were skipped. This happens when a v0.4.x intermediate binary ran migration that set version 12 without completing all ALTER TABLE statements.

    Fix approach:

    1. Add ensure_documents_has_children() guard in ensure_schema_version() — checks version >= 12 and column exists, adds if missing
    2. Hook into uteke repair to fix partial migrations
  3. ajianaz commented on Jun 30, 2026

    @ajianaz
    CollaboratorAuthor

    Fixed in #504 — ensure_documents_has_children() runs on every DB open + uteke repair now fixes schema inconsistencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugscope:core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions