Skip to content

Bug: gbrain init --migrate-only fails due to idx_ingest_log_source_type_created on existing databases #1040

@codxt

Description

@codxt

Describe the bug
When running gbrain init --migrate-only against an existing database
(from a version prior to v0.31.2 / v47), the initialization crashes because
schema.sql tries to create the idx_ingest_log_source_type_created index
on the source_id column before migration v47 has had a chance to add
that column to the ingest_log table.

To Reproduce

  1. Have an existing database initialized prior to v0.31.2 (migration < v47).
  2. Upgrade gbrain to the latest version.
  3. Run gbrain init --migrate-only (or gbrain init).
  4. See error:
    ERROR: column "source_id" does not exist at character 21748
    STATEMENT:
    -- GBrain Postgres + pgvector schema
    ...
    CREATE INDEX IF NOT EXISTS idx_ingest_log_source_type_created
    ON ingest_log (source_id, source_type, created_at DESC);

Expected behavior
The base schema.sql should not attempt to create indexes on columns that might not exist yet if a database is undergoing migrations. The index creation should ideally be handled within the migration file itself or deferred until after migrations have run.

Workaround
Currently, deployments (like Docker builds) have to patch src/schema.sql, src/core/schema-embedded.ts, and src/core/pglite-schema.ts via sed to comment out the idx_ingest_log_source_type_created index creation before
running bun install.

Environment

  • gbrain version: v0.35.0.0 (commit baf1a47798cb145d00bfce4fa94f85a94c8d7e07)

  • OS: Debian 12 Bookworm (Docker on Railway)

  • Bun version: 1.3.13

  • Database: Railway Postgres (Self-hosted Postgres)
    gbrain doctor --json output
    {
    "error": "Cannot run gbrain doctor because the container crashes during
    gbrain init --migrate-only on startup."
    }

    (Note: Because the migration crashes the initialization script before the
    application can start, gbrain doctor cannot be successfully executed.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions