Skip to content

fix(db): restore channel-aware path — ECS was opening wrong database file - #75

Merged
hblanken merged 1 commit into
collabfrom
fix/db-channel-path
Aug 19, 2026
Merged

fix(db): restore channel-aware path — ECS was opening wrong database file#75
hblanken merged 1 commit into
collabfrom
fix/db-channel-path

Conversation

@hblanken

Copy link
Copy Markdown
Collaborator

Root cause

The ECS deployment after PR #72/#73 was opening a fresh opencode.db while all production data lived in opencode-local.db. This caused the drizzle SQL migration to immediately crash with:

Failed to run the query 'ALTER TABLE `session` ADD `metadata` text;'

Because the fresh opencode.db had no session table yet.

Why this happened

The upstream sync (PR #72) simplified getPath() in db.ts to always return opencode.db:

// NEW (broken in ECS)
return path.join(Global.Path.data, "opencode.db")

But packages/core/src/database/database.ts uses a channel-suffixed path, and the pre-PR72 db.ts also used a channel-aware path. When OPENCODE_CHANNEL is not bundled (which is the case on ECS, since the server runs from TypeScript source), InstallationChannel = "local" and the channel path is opencode-local.db.

So in ECS:

Path opened
Old db.ts opencode-local.db
database.ts opencode-local.db
New db.ts (broken) opencode.db
New db.ts (fixed) opencode-local.db

Fix

Restore the channel-suffix logic in db.ts's getPath(), matching both the old behavior and database.ts. Also adds OPENCODE_DISABLE_CHANNEL_DB support for parity with database.ts.

Verification

Tested with a production-accurate EFS database (20 old SQL migration records, full schema at opencode-local.db):

[db] opening database { path: "...opencode-local.db" }
[db] applying migrations { count: 1, mode: "dev" }
opencode server listening on http://0.0.0.0:4097

Server starts cleanly. PR #74's legacy migration seeding fix still runs correctly on top of this.

Next steps

Merge this PR, then trigger deploy-collab.yml.

… behavior

The upstream sync (PR #72) simplified getPath() in db.ts to always return
opencode.db, but packages/core/src/database/database.ts still uses a
channel-suffixed path (opencode-local.db when InstallationChannel="local",
which is the case on ECS where OPENCODE_CHANNEL is not bundled).

The pre-PR72 db.ts also used a channel-aware path (getChannelPath).  Losing
the suffix meant db.ts opened a fresh opencode.db on ECS while all production
data was in opencode-local.db, causing the drizzle SQL migration to fail with
"ALTER TABLE session ADD metadata text" on a database with no session table.

Fix: restore the channel-suffix logic (matching both old db.ts and database.ts)
and also honour OPENCODE_DISABLE_CHANNEL_DB for parity with database.ts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7cee404d-6776-4b81-a7b5-0e5093937b41


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hoj-unleash
hoj-unleash self-requested a review August 19, 2026 04:51

@hoj-unleash hoj-unleash left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maximum push.

@hblanken
hblanken merged commit 0c9a8a5 into collab Aug 19, 2026
4 of 8 checks passed
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