Summary
On Windows, OpenCode Desktop v1.18.1 initially failed to start against an existing local database with able project already exists. After recovering the legacy schema enough for v1.18.1 to complete its official migrations, Desktop starts, but it shows no historical projects or sessions. The v1.18.1 CLI reads the same database and lists the historical sessions correctly.
Environment
- OS: Windows
- OpenCode Desktop: 1.18.1
- OpenCode CLI: 1.18.1 (npm global install)
- Database: %USERPROFILE%/.local/share/opencode/opencode.db`n
Original failure
Desktop startup repeatedly failed with:
ext Failed to run the query 'CREATE TABLE project (...)' Caused by: table project already exists
The database already contained the project table and historical data. Its legacy Drizzle journal was inconsistent: __drizzle_migrations had repeated 20260428004200_add_session_path entries, while the newer migration journal contained only that migration ID. v1.18.1 therefore attempted to replay the initial migration.
Database evidence before/after recovery
The original database contained, and the recovered database still contains:
- 3 projects
- 20 sessions
- 539 messages
- 2176 parts
- PRAGMA integrity_check returns ok`n
After the recovery, all 38 migrations from v1.18.1 are recorded in the migration table. The historical data counts above were retained.
Recovery steps attempted
I first backed up the database and then followed the workaround in #16678 to backfill old Drizzle migration names. This exposed real schema drift because some legacy migration IDs were present even though their schema changes had never run.
The verified missing official changes were:
- 20260303231226_add_workspace_fields: the existing empty workspace table was missing ype,
ame, directory, and extra; this was the source of
o such column: type.
- 20260227213759_add_session_workspace_id: session.workspace_id was absent.
- 20260428004200_add_session_path: session.path was absent.
Those were applied using the exact SQL from the v1.18.1 migration source. Then the v1.18.1 Desktop migration runner completed all remaining official migrations.
Current problem
Desktop now starts successfully, but it shows no historical projects and no historical sessions.
The CLI can read the same DB correctly:
powershell opencode --version # 1.18.1 opencode session list
For example, running opencode session list from C:/Users/ returns historical sessions. Direct SQL also returns all 20 rows from session.
18 historical sessions still have session.project_id = 'global' and are distributed across several historical directories, including:
- C:/Users/
n- C:/Users/<user>/Downloadsn- D:/myera/2-3Bn- D:/myera/apkn- D:/myera/opencode_testn- D:/myera/powerShown- E:/workspace/mypaperguru`n
The current project_directory table is empty. The current project table has only global plus two old Git project rows. This appears to leave Desktop without a persisted index of the historical directories after migration/cache recovery.
Desktop state/cache attempt
I also tested the workaround discussed in #36064: closed Desktop, backed up, removed only %APPDATA%/ai.opencode.desktop/opencode.global.dat and %APPDATA%/ai.opencode.desktop/opencode.workspace.*.dat, then restarted. This did not restore visibility. Restoring the backed-up Desktop state files also did not restore historical projects/sessions. No session/message/part data was deleted.
Expected behavior
- v1.18.1 should migrate this legacy database without replaying CREATE TABLE project.
- After migration, Desktop should discover/index the directories represented by existing historical sessions, or otherwise display/recover those sessions.
- Desktop and CLI should present the same historical sessions from the same database.
Related
Request
Please provide or merge a supported recovery path for legacy databases where migration journal entries and actual schema drift apart, including reconstruction of Desktop project/directory indexing from persisted sessions. I can provide sanitized schema dumps or additional SQL output if useful.
Summary
On Windows, OpenCode Desktop v1.18.1 initially failed to start against an existing local database with able project already exists. After recovering the legacy schema enough for v1.18.1 to complete its official migrations, Desktop starts, but it shows no historical projects or sessions. The v1.18.1 CLI reads the same database and lists the historical sessions correctly.
Environment
Original failure
Desktop startup repeatedly failed with:
ext Failed to run the query 'CREATE TABLE project (...)' Caused by: table project already existsThe database already contained the project table and historical data. Its legacy Drizzle journal was inconsistent: __drizzle_migrations had repeated 20260428004200_add_session_path entries, while the newer migration journal contained only that migration ID. v1.18.1 therefore attempted to replay the initial migration.
Database evidence before/after recovery
The original database contained, and the recovered database still contains:
After the recovery, all 38 migrations from v1.18.1 are recorded in the migration table. The historical data counts above were retained.
Recovery steps attempted
I first backed up the database and then followed the workaround in #16678 to backfill old Drizzle migration names. This exposed real schema drift because some legacy migration IDs were present even though their schema changes had never run.
The verified missing official changes were:
ame, directory, and extra; this was the source of
o such column: type.
Those were applied using the exact SQL from the v1.18.1 migration source. Then the v1.18.1 Desktop migration runner completed all remaining official migrations.
Current problem
Desktop now starts successfully, but it shows no historical projects and no historical sessions.
The CLI can read the same DB correctly:
powershell opencode --version # 1.18.1 opencode session listFor example, running opencode session list from C:/Users/ returns historical sessions. Direct SQL also returns all 20 rows from session.
18 historical sessions still have session.project_id = 'global' and are distributed across several historical directories, including:
n- C:/Users/<user>/Downloadsn- D:/myera/2-3Bn- D:/myera/apkn- D:/myera/opencode_testn- D:/myera/powerShown- E:/workspace/mypaperguru`nThe current project_directory table is empty. The current project table has only global plus two old Git project rows. This appears to leave Desktop without a persisted index of the historical directories after migration/cache recovery.
Desktop state/cache attempt
I also tested the workaround discussed in #36064: closed Desktop, backed up, removed only %APPDATA%/ai.opencode.desktop/opencode.global.dat and %APPDATA%/ai.opencode.desktop/opencode.workspace.*.dat, then restarted. This did not restore visibility. Restoring the backed-up Desktop state files also did not restore historical projects/sessions. No session/message/part data was deleted.
Expected behavior
Related
project" and logging issues #16678: CREATE TABLE project migration-journal failureRequest
Please provide or merge a supported recovery path for legacy databases where migration journal entries and actual schema drift apart, including reconstruction of Desktop project/directory indexing from persisted sessions. I can provide sanitized schema dumps or additional SQL output if useful.