Repository navigation
feat: auto-detect SQLite schema changes from external tools (#704) - #719
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SQLite databases modified by external tools (migration runners, CLI, other clients) now auto-refresh the sidebar and autocomplete cache without requiring manual Cmd+R.
Closes #704
Architecture
Two-layer detection using native macOS
DispatchSource:File watcher (
DatabaseFileWatcher) — monitors the.sqlitefile viaDispatchSource.makeFileSystemObjectSourcewithO_EVTONLY. Re-creates the file descriptor after each event to handle SQLite journaling (which invalidates the original inode via rename operations). 500ms debounce coalesces rapid writes.Window focus fallback — when a main window regains key status for a file-based connection,
refreshTablesIfStale()runs if not recently refreshed (2-second dedup). Catches edge cases the file watcher might miss.Both layers call the existing
refreshTables()which updates sidebar + autocomplete cache.Root cause of the original bug
refreshTables()was only called on Cmd+R (manual) or on initial connection. No mechanism existed to trigger it when the SQLite file was modified externally.Root cause of the fd invalidation
SQLite journaling renames the database file during commits. The
DispatchSource's file descriptor then points to the old inode, not the file at that path. Fix: re-open the fd after every event.Changes
DatabaseFileWatcher.swiftMainContentCoordinator.swiftrefreshTablesIfStale()with 2s dedupMainContentView.swiftTest plan
sqlite3 path/to/db "CREATE TABLE test (id INTEGER PRIMARY KEY)"→ sidebar showstestwithin ~1 secondsqlite3 path/to/db "DROP TABLE test"→ sidebar removestestwithin ~1 secondsqlite3 path/to/db "ALTER TABLE users ADD COLUMN phone TEXT"→ click table, new column visible