Skip to content

fix(database): unify session DB — remove channel-based path splitting - #190

Merged
jeonghun-jj-lee merged 2 commits into
local/amicodefrom
unified-session-db
Aug 12, 2026
Merged

jeonghun-jj-lee merged 2 commits into
local/amicodefrom
unified-session-db

Conversation

@jeonghun-jj-lee

@jeonghun-jj-lee jeonghun-jj-lee commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Closes #188

Summary

Removes all channel-based database path logic. All channels now write to opencode.db. A one-time consolidation on first startup merges rows from legacy channel-named DBs (opencode-*.db) via ATTACH + INSERT OR IGNORE per table, then backs up sources as *.db.merged.

Changes

  • Removed: STABLE_CHANNELS, consolidateLocalDb, InstallationChannel import, and OPENCODE_DISABLE_CHANNEL_DB env var logic
  • Simplified path(): returns join(Global.Path.data, "opencode.db") for all channels (OPENCODE_DB env var override retained)
  • Added consolidateChannelDbs(targetPath): runs once synchronously at startup via bun:sqlite:
    • Finds all opencode-*.db files (skips *.db.merged)
    • If opencode.db doesn't exist, renames the largest source to become it (no full copy)
    • Merges remaining sources: checkpoint WAL, ATTACH, INSERT OR IGNORE per table, DETACH, rename to *.db.merged
    • Foreign keys disabled during merge, re-enabled after
    • Idempotent: partial failures leave sources un-renamed for retry on next startup
    • Skipped entirely when OPENCODE_DB env var is set

Standalone script

A merge-opencode-dbs.sh bash script (using sqlite3 CLI) is available separately for users who want to merge before upgrading.

Summary by CodeRabbit

  • Data Management
    • Consolidated channel-specific databases into a single opencode.db.
    • Automatically merges existing databases during startup while preserving records and removing duplicates.
    • Retains support for explicitly configured database paths.
    • Improves recovery with retry handling, backups, and cleanup of temporary database files.
  • Documentation
    • Added documentation describing the unified database approach and migration behavior.

…#188)

- Remove STABLE_CHANNELS, consolidateLocalDb, OPENCODE_DISABLE_CHANNEL_DB logic
- path() now returns opencode.db for all channels (OPENCODE_DB override retained)
- Add consolidateChannelDbs(): one-time startup merge of legacy opencode-*.db
  files via ATTACH + INSERT OR IGNORE per table
- Largest DB promoted by rename (no full copy); sources renamed to *.db.merged
- Foreign keys disabled during merge; WAL checkpointed on sources before ATTACH
- Idempotent: partial failures leave sources for retry on next startup
@jeonghun-jj-lee
jeonghun-jj-lee merged commit 61a05ed into local/amicode Aug 12, 2026
1 of 5 checks passed
@jeonghun-jj-lee
jeonghun-jj-lee deleted the unified-session-db branch August 12, 2026 22:37
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e2fdf2b2-3a9f-455c-9c41-285b7c3db7b0

📥 Commits

Reviewing files that changed from the base of the PR and between 151d263 and f1aa7d8.

📒 Files selected for processing (2)
  • docs/adr/0004-unified-session-database.md
  • packages/core/src/database/database.ts

📝 Walkthrough

Walkthrough

The PR unifies session storage in opencode.db. Startup consolidates legacy channel databases with deduplication, backups, WAL cleanup, retries, and largest-file promotion. Explicit OPENCODE_DB overrides remain supported. The ADR documents the behavior and design decisions.

Changes

Unified session database

Layer / File(s) Summary
Legacy database consolidation
packages/core/src/database/database.ts
Startup discovers opencode-*.db files, merges tables with INSERT OR IGNORE, checkpoints WAL files, handles foreign keys and transactions, renames merged sources, removes sidecars, and retries failures.
Canonical database routing
packages/core/src/database/database.ts, docs/adr/0004-unified-session-database.md
Default routing uses opencode.db and removes channel-specific path logic. The ADR documents consolidation, backup, override, and migration behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: jlongster

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch unified-session-db

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

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.

Unify session database: remove channel-based DB path splitting

1 participant