fix(db,desktop): cascade host's workspaces on host delete
Problem
Deleting a host from Settings → Hosts fails whenever the host still owns workspace rows. v2_workspaces_host_fk was defined without an onDelete clause (defaults to NO ACTION), so the DELETE FROM v2_hosts in v2Host.delete is rejected by Postgres and the raw FK-violation message lands in the error toast.
This is unavoidable for stale duplicate devices: repo-root (main) workspaces can't be deleted through the normal workspace-delete action, so they pin the dead host forever.
Reported by a user (support, 2026-07-16) with a stale host left behind by an uninstalled build; they confirmed cascade-deleting the dead host's workspaces is the desired behavior.
Fix
- Add
.onDelete("cascade")tov2_workspaces_host_fk(matches the existing cascade onv2_users_hosts_host_fk). Migration0061_v2_workspaces_host_fk_cascadedrops and re-adds the constraint. - Update the delete-host dialog copy, which previously promised "Workspaces, files, conversations, and automations stay" — impossible under the old FK and wrong under the new behavior. It now says the host's workspaces are removed and files on the machine stay.
Downstream is safe: chat_sessions.v2_workspace_id is SET NULL, and nothing else hard-references v2_workspaces.
Notes
- Migration generated with
drizzle-kit generate; no hand-edits topackages/db/drizzle/. - Should be applied via the API/cloud deploy before any desktop build leans on it (standard ordering).
Verification
bun run typecheckpasses; Biome clean on changed files.- Root
bun run lintcurrently fails on unrelated pre-existing nested.conductor/*Biome root configs, not on this change.
Summary by cubic
Fixes host deletion by cascading the host’s v2_workspaces on delete. Updates the desktop delete-host dialog to clarify that the host’s workspaces are removed and files on the machine stay.
- Migration
- Apply
0061_v2_workspaces_host_fk_cascadebefore shipping desktop; it recreatesv2_workspaces_host_fkwith ON DELETE CASCADE. - Downstream is safe:
chat_sessions.v2_workspace_iduses SET NULL.
- Apply
Summary by CodeRabbit
-
User Experience
- Updated host deletion messaging to clearly explain that deleting a host also removes its access and associated workspaces.
- Clarified that files remain on the machine after deletion.
- Added a warning that a running host may reappear and that deletion cannot be undone.
-
Bug Fixes
- Ensured associated workspaces are automatically removed when their host is deleted, keeping host and workspace data consistent.