move to using a global database - #20
Conversation
Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
Replace per-project SQLite databases with a single global database at ~/.local/share/anvil/anvil.db. Sessions are now discoverable from any directory, MCP OAuth tokens are shared across projects, and cross-project search becomes possible. Key changes: - Add working_dir column to sessions for project association - Add ConnectGlobal/ReleaseGlobal with shared connection pool - Migration engine with sync (trigger-drop) and batched (trigger-tolerant) modes, OAuth newest-wins conflict resolution, ATTACH DATABASE for cross-DB copy - Thread working_dir through 11 interface layers (session.Service -> Workspace -> Backend -> HTTP -> UI) - Add --session/-s, --there, --skip-migration CLI flags - TUI sessions dialog defaults to current directory with ctrl+a toggle - Stats show global totals - Rename DataDirectory to ProjectDirectory - Remove dead ListLatestSessionFiles/ListNewFiles queries - Switch filetracker to absolute paths Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
- Document OAuth token concurrent-migration race condition as accepted behavior in migrate.go - Improve --there error message when working directory no longer exists to suggest alternatives (--cwd or omitting --there) Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
- Add Windows absolute path detection (drive letter patterns like C:\ and C:/) alongside Unix (/) in read_files relative-to-absolute conversion - Update AGENTS.md persistence section to reflect global database architecture Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
- Use context.Background() for DETACH DATABASE in defer to prevent connection pool pollution when parent context is canceled - Add UNC path detection (\server\share) in read_files migration - Add backwards compatibility for deprecated data_directory config key; automatically migrates to project_directory during config loading Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
…migrate Eliminates the db → projects layering violation by moving application-level data migration logic out of the infrastructure package. internal/db stays focused on connections, sqlc queries, and schema migrations. The new internal/migrate package owns the ATTACH-based copy engine, OAuth conflict resolution, startup orchestration, and project discovery dependency. Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
The migration engine moved from internal/db/migrate.go to internal/migrate/ in fe774ab. Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
Add ResetMigration/ResetAllMigrations to clear completion markers so partially-failed migrations can be re-run. Add --force-migration CLI flag that clears all markers before migrating. Add per-stage logging to migrateBatched for observability. Document re-run safety guarantees (INSERT OR IGNORE ensures idempotent replay without duplicates). Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
Co-authored-by: Brodie Westrope brodie.westrope@gmail.com
PR Type
Enhancement
Description
Migrate from per-project SQLite databases to a single global database
Add
working_dircolumn to sessions for project associationImplement migration engine with sync and batched modes using ATTACH DATABASE
Thread
working_dirthrough session service, workspace, backend, and UI layersAdd
--there,--session/-s,--skip-migration, and--allCLI flagsRename
DataDirectorytoProjectDirectory; remove dead queriesDiagram Walkthrough
File Walkthrough
14 files
Migration engine with sync and batched modes via ATTACH DATABASEStartup migration helpers for current and all projectsUpdate prepared statements for renamed and new queriesAdd working_dir to session queries and new list/get variantsReplace dead queries with session-scoped ListSessionFilesByPathAdd ListUserMessagesByWorkingDir queryAdd WorkingDir field to Session modelAdd ConnectGlobal/ReleaseGlobal with shared connection poolMigration adding working_dir column and migrations_completed tableThread working_dir through session service interface and methodsRename DataDirectory to ProjectDirectory with deprecation aliasUpdate config loading for ProjectDirectory renameAdd --there, --skip-migration flags and global DB setupAdd --all flag to session list; filter by working dir6 files
Comprehensive tests for project DB migration scenariosTests for global database connection managementTests for working_dir persistence, filtering, and inheritanceUpdate tests for DataDirectory to ProjectDirectory renamePass working_dir to session Create calls in testsPass working_dir to session Create calls in coordinator tests52 files