2code icon indicating copy to clipboard operation
2code copied to clipboard

Task 8: Drop sqlite `profiles` (and mapping tables)

Open AkaraChen opened this issue 2 months ago • 0 comments

Summary

Drop sqlite profiles and mapping tables for parent plan #436. After Task 7 (#449 on task-7-herdr-live-cwd) Git, the file tree, and watchers already resolve checkout from live Herdr cwd, but leftover profiles, profile_runtime_mappings, session_runtime_mappings, and herdr_namespaces still exist. Notes still live on profiles.notes and overlay by leftover worktree_path. Local-flag list/create/delete still treat sqlite extras as a nested catalog. This task moves notes to a 2code table keyed by project_id + canonical checkout path, then DROPs those tables. projects / project_groups stay. pty_sessions stays until Task 9 (Local PTY), but its FK to profiles cannot.

A profile remains an open Herdr workspace. The profile id is the Herdr workspace_id (wN). Join key: canonical projects.folder ↔ live checkout / pane cwd (Task 1 contract, docs/herdr-integration.md). Do not store notes in Herdr. Do not reintroduce mapping / worktree_path authority. Do not delete Local PTY (Task 9). Do not launch/adopt the project-folder default (Task 10). Do not start a second events.subscribe / name HerdrRuntimeSync in lib.rs. Pin stays v0.9.0. TWOCODE_RUNTIME=local remains until Task 9. Local must never own a worktree Herdr already owns.

This branch is the chosen resolution for #446 (drop leftover sqlite extras so Local-flag delete cannot git worktree remove a Herdr-open checkout). Finish removing leftover sqlite UUID joins called out in #447 (sqlite_profile_id_for_checkout, live_workspace_for_sqlite_profile). Do not implement a live-path Local-delete lock instead of DROP.

Dependencies: Parent plan #436. Prerequisites: #437 (Task 1), #439 (Task 2), #441 (Task 3), #443 (Task 4), #445 (Task 5), #448 (Task 6), #449 (Task 7). Open #438, #440, #442, #444, #450 are line-count tracking only — not blockers. Open #446 / #447 are resolved by this DROP / leftover-UUID removal, not by restoring mappings. Open #394 issues #395–#434 (including #394 Task 8 / #417) must not be implemented or closed here.

Work to complete

  1. Move notes off profiles before DROP

    • Add a 2code sqlite table (suggested name checkout_notes) keyed by project_id (FK → projects.id ON DELETE CASCADE) + canonical checkout_path. Columns: notes text, created_at. Unique on (project_id, checkout_path). Do not key notes by Herdr workspace_id. Do not store notes in Herdr.
    • One-shot migrate non-empty leftover profiles.notes whose worktree_path is non-empty into that table (same path-equality helper as today's overlay). Then overlay/list/update read this table only.
    • notes_overlay / update_notes_with_runtime: Herdr save upserts by live cwd from reconcile_profile_checkout. A Herdr-only workspace with no leftover row can save notes (closes the Task 5 empty-notes hole). Do not INSERT a profiles stub. Do not invent a sqlite UUID.
    • IPC DTO Profile (id, notes, is_default, worktree_path, …) stays as a derived GUI type. Decouple it from Diesel #[diesel(table_name = profiles)]. Notes UI (ProfileNotesEditor, useUpdateProfileNotes) keeps the same clicks/labels.
    • Delete notes rows only via project CASCADE (and optional cleanup when a checkout path is gone). Do not fail Herdr worktree.remove if a notes row is missing.
  2. Diesel DROP + pty_sessions FK

    • New embedded migration, in order: create checkout_notes + copy leftover notes; recreate pty_sessions without REFERENCES profiles(id) and with project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE (copy project_id from the old profiles join; fallback default-{project_id} → that project); DROP session_runtime_mappings, profile_runtime_mappings, herdr_namespaces, then profiles. Keep projects / project_groups. Do not DROP pty_sessions (Task 9).
    • Regenerate src-tauri/crates/model/src/schema.rs via Diesel (diesel print-schema / project convention). Do not hand-edit schema. Remove Diesel NewProfile / table-backed Profile / mapping models once unused.
    • repo::pty::list_by_project must filter on pty_sessions.project_id, not INNER JOIN profiles.
  3. Delete leftover sqlite profile / mapping seams

    • Stop insert_default on create_from_folder and every other production caller. New projects are projects rows only. Empty Herdr → profiles: [] until Task 10 (already named).
    • Remove production reads/writes of profiles / mapping tables: repo::profile CRUD, repo::runtime_mapping bind/unbind/find, import_leftover_sqlite_profiles (no leftover extras to import), sqlite_profile_id_for_checkout, live_workspace_for_sqlite_profile / leftover UUID branch of bound_workspace, refuse_mapped_without_runtime. Herdr create dual-backend refuse uses live worktree.list / snapshot only, not sqlite extras.
    • Herdr list/create/close/session-store/Git/FS/watcher stay on the Task 3–7 live seams. Do not fall back to sqlite when Herdr is empty or down.
  4. Local flag without a profiles catalog

    • TWOCODE_RUNTIME=local still exists until Task 9. Nested sqlite extras are gone.
    • Local list synthesizes at most one implicit default checkout per project from projects.folder (id = default-{project_id}, is_default = true, notes from checkout_notes for that folder). Do not list leftover extras. Do not git worktree add / git worktree remove.
    • Local New Profile / Delete Profile for extras fail closed. Local delete of the implicit default stays refused (primary). Local Git/FS/watcher/PTY use projects.folder for that synthetic id (reconcile_local_profile_checkout). Local PTY may keep writing pty_sessions with unconstrained profile_id = default-{project_id} and project_id set.
    • Named UX exception (Local flag only): the old nested sqlite profile catalog cannot be backed without profiles. Default Herdr GUI clicks/labels stay New Profile / Delete Profile. Do not add a Settings runtime toggle. Do not flip the selector to Local.
  5. Prove without swallowing later tasks

    • Colocated / integration tests: after migrate, profiles / mapping / herdr_namespaces tables are absent; projects remain; leftover notes round-trip on checkout_notes by path; Herdr-only workspace notes save without a sqlite UUID; Herdr list still live workspace_id; create_from_folder does not INSERT a profile row; Local list is the synthetic folder checkout only; Local extras create/delete fail closed (no git remove); Herdr-down does not sqlite-fill; list_by_project sessions do not JOIN profiles; production source guards (no insert_default / mapping bind / import_leftover_sqlite_profiles / HerdrRuntimeSync / events.subscribe in lib.rs).
    • Rewrite or delete tests that INSERT INTO profiles / bind_profile_workspace as production fixtures. Keep Local-flag coverage for the synthetic folder checkout + fail-closed extras.
    • Update docs/herdr-integration.md: Task 8 done on this branch; notes live on checkout_notes; mapping/profiles DROPped; pty_sessions remains until Task 9; Local nested extras gone. Do not bump v0.9.0. If line count grows past the estimate, open a tracking issue; do not fold Task 9–10 into this branch.

Likely files and directories

  • New: src-tauri/migrations/<timestamp>_drop_profiles_and_runtime_mappings/ — checkout_notes, pty_sessions recreate, DROP mappings + profiles.
  • Update: src-tauri/crates/model/src/schema.rs (regenerate), src-tauri/crates/model/src/profile.rs, src-tauri/crates/model/src/runtime_mapping.rs, src-tauri/crates/model/src/pty.rs (project_id on session records).
  • Update: src-tauri/crates/repo/src/profile.rs (remove or replace with checkout_notes repo), src-tauri/crates/repo/src/runtime_mapping.rs, src-tauri/crates/repo/src/pty.rs, src-tauri/crates/repo/src/project.rs (list_all_with_profiles).
  • Update: src-tauri/crates/service/src/project.rs, src-tauri/crates/service/src/profile.rs, src-tauri/crates/service/src/runtime_adoption.rs, src-tauri/crates/service/src/runtime.rs, src-tauri/crates/service/src/runtime/herdr.rs, src-tauri/crates/service/src/runtime/local.rs (mapping lock only; do not delete Local PTY).
  • Update: docs/herdr-integration.md — Task 8 done on this branch.
  • Update tests: colocated service/repo tests plus src-tauri/tests/integration_project.rs, src-tauri/tests/integration_pty_db.rs, src-tauri/tests/integration_migrations.rs.
  • Touch only if IPC DTO fields change: src-tauri/src/handler/profile.rs, frontend notes hooks. bun run typegen if signatures change; do not edit src/generated/ by hand.
  • Do not change: Local PTY spawn/adapter internals (Task 9), sidecar pin, Settings runtime toggle, launch/adopt on project open (Task 10), Git/file-tree/notes UI redesign, lib.rs naming HerdrRuntimeSync.

Estimated changes: 500–800 lines total, additions plus deletions, including tests and migration SQL; excluding generated files, lockfile churn and binary artifacts. Material scope growth should become a separate issue.

Acceptance criteria

  • [ ] Diesel migration DROPs profiles, profile_runtime_mappings, session_runtime_mappings, and herdr_namespaces. projects / project_groups remain. sqlite profiles is not source of truth and is not a table.
  • [ ] Notes live on a 2code checkout_notes (or equivalent) table keyed by project_id + canonical checkout path. They are not stored in Herdr. Herdr-only workspaces can save/load notes via live cwd. Overlay no longer reads profiles.notes.
  • [ ] pty_sessions remains for Local until Task 9, with project_id and no FK to profiles. Herdr still must not INSERT/UPDATE/DELETE pty_sessions.
  • [ ] create_from_folder / Herdr create/delete / leftover import do not write profiles or mapping rows. Leftover UUID joins (sqlite_profile_id_for_checkout, live_workspace_for_sqlite_profile) are gone. import_leftover_sqlite_profiles is gone.
  • [ ] TWOCODE_RUNTIME=local lists only the synthetic projects.folder default (no nested extras). Local extras create/delete fail closed and do not git worktree remove. Default Herdr New Profile / Delete Profile clicks and labels stay.
  • [ ] Named UX exceptions: route ids are workspace_id; tab ids are pane_id; empty Herdr profile list until Task 10; splits flattened as extra tabs; non-git New Profile is folder workspace.create; Local-flag nested sqlite extras are gone (old Local catalog cannot be backed without profiles). The Task 5 “Herdr-only notes stay empty” exception is closed.
  • [ ] No launch/adopt of the project-folder default. No Local PTY deletion. No second events.subscribe. lib.rs still does not name HerdrRuntimeSync. Pin stays v0.9.0. GUI exit still does not server stop.
  • [ ] Tests: cargo test --workspace from src-tauri (or cargo test --workspace --exclude code where GTK is unavailable). Frontend lint/typecheck/tests if frontend scope is introduced. bun run typegen if IPC signatures change; do not edit src/generated/ by hand.
  • [ ] No pull request until parent #436 is complete.

Out of scope

  • Deleting the Local PTY runtime, Local adapter, or DROPping pty_sessions (Task 9).
  • Launch/adopt of the project-folder default (worktree.open / workspace.create on project open) (Task 10).
  • Reintroducing profile_runtime_mappings / a path-cache column as authority, or a live-path Local-delete lock as a substitute for DROP (#446 is resolved by this DROP).
  • Starting a new HerdrRuntimeSync / events.subscribe, changing the v0.9.0 pin, or #394 Task 16 / #432.
  • Implementing or closing #394 issues #395–#434 (including #394 Task 8 / #417) or line-count trackers.
  • Opening a pull request.

Standing constraints

  • Do not treat sqlite profiles as source of truth. Do not add a path cache that can disagree with live Herdr and still win.
  • projects (and project groups / notes-as-2code-data) remain 2code sqlite.
  • Join key remains path ↔ live Herdr cwd/worktree group.
  • Never let Local and Herdr own the same worktree.
  • Preserve existing 2code interaction. UX change is allowed only when Herdr cannot back the old clicks/labels; this task names one new exception: Local-flag nested sqlite extras are gone. Default Herdr GUI is unchanged aside from notes now working on Herdr-only workspaces.
  • One task; stack on task-7-herdr-live-cwd. Do not open a PR until the parent plan is complete.

AkaraChen avatar Sep 16 '26 08:09 AkaraChen