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
- Have an existing database initialized prior to
v0.31.2 (migration < v47).
- Upgrade
gbrain to the latest version.
- Run
gbrain init --migrate-only (or gbrain init).
- 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.)
Describe the bug
When running
gbrain init --migrate-onlyagainst an existing database(from a version prior to v0.31.2 / v47), the initialization crashes because
schema.sqltries to create theidx_ingest_log_source_type_createdindexon the
source_idcolumn before migrationv47has had a chance to addthat column to the
ingest_logtable.To Reproduce
v0.31.2(migration< v47).gbrainto the latest version.gbrain init --migrate-only(orgbrain init).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.sqlshould 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, andsrc/core/pglite-schema.tsviasedto comment out theidx_ingest_log_source_type_createdindex creation beforerunning
bun install.Environment
gbrain version:
v0.35.0.0(commitbaf1a47798cb145d00bfce4fa94f85a94c8d7e07)OS: Debian 12 Bookworm (Docker on Railway)
Bun version:
1.3.13Database: Railway Postgres (Self-hosted Postgres)
gbrain doctor --jsonoutput{
"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 doctorcannot be successfully executed.)