Skip to content

refactor: migrate settings source of truth to config.json - #115

Merged
h4yfans merged 3 commits into
mainfrom
refactor/settings-config-json-clean
Mar 29, 2026
Merged

refactor: migrate settings source of truth to config.json#115
h4yfans merged 3 commits into
mainfrom
refactor/settings-config-json-clean

Conversation

@h4yfans

@h4yfans h4yfans commented Mar 29, 2026

Copy link
Copy Markdown
Collaborator

What

Move portable user preferences from SQLite-only storage to <vault>/.memry/config.json as the source of truth. SQLite becomes a read cache for fast IPC performance.

Why

User preferences stored in SQLite are opaque when copying a vault to a new machine pre-sign-in. Additionally, mergeRemote() wrote to synced_settings key but never propagated to the general key the UI reads — settings from other devices were invisible until app restart.

How

  • VaultPreferences Zod schema + readPreferences()/writePreferences() for config.json I/O with deep-partial merge
  • SET_GENERAL_SETTINGS / SET_EDITOR_SETTINGS: write config.json first (source of truth), then update SQLite cache. Only portable fields go to config.json; startOnBoot, onboardingCompleted stay SQLite-only
  • Vault open flow: migrateSettingsToConfig() — if config.json has preferences, use them; if missing, seed from SQLite (one-time backwards-compatible migration)
  • settingsHandler.applyUpsert: after mergeRemote(), propagates merged data to config.json, updates SQLite cache, and broadcasts CHANGED events — fixes the synced_settings→general key gap
  • Defensive: propagateMergedSettings and broadcastSettingsChanged gracefully handle missing vault path, database, or BrowserWindow (test environments, edge cases)

Type

  • refactor — restructure without behavior change

Test plan

  • Unit tests added/updated
  • Integration tests added/updated

68 new tests across 5 test files:

  • vault-preferences.test.ts (15) — schema validation, read/write, partial merge, corruption recovery
  • settings-cache.test.ts (7) — SQLite cache population, migration from SQLite→config.json, machine-local field preservation
  • settings-handlers.test.ts (+6 = 29 total) — config.json write-through for portable/local/editor fields
  • settings-handler.test.ts (6) — sync merge propagation to config.json + CHANGED broadcast
  • apply-item.test.ts (25) — existing integration tests still pass

Checklist

  • Self-reviewed the diff
  • No hardcoded secrets or credentials
  • Files stay under ~500 LOC
  • Follows immutable data patterns

h4yfans added 3 commits March 29, 2026 19:52
Move portable user preferences (theme, font, editor width, etc.) from
SQLite-only storage to <vault>/.memry/config.json as the source of truth.
SQLite becomes a read cache for fast IPC performance.

Key changes:
- VaultPreferences Zod schema + readPreferences/writePreferences helpers
- SET_GENERAL_SETTINGS and SET_EDITOR_SETTINGS write config.json first,
  then update SQLite cache
- Vault open flow migrates: if config.json has preferences, use them;
  if missing, seed from SQLite (one-time migration)
- settingsHandler.applyUpsert now propagates merged sync data to
  config.json, updates SQLite cache, and broadcasts CHANGED events
  (fixes the synced_settings → general key gap)
- Machine-local settings (startOnBoot, onboardingCompleted, etc.) stay
  in SQLite only

68 new/updated tests across 5 test files, all passing.
Use schema/index import for DrizzleDb type compatibility and fix
editor seed object typing in migrateSettingsToConfig.
@h4yfans
h4yfans merged commit a165d3c into main Mar 29, 2026
2 checks passed
@h4yfans
h4yfans deleted the refactor/settings-config-json-clean branch March 29, 2026 17:04
h4yfans added a commit that referenced this pull request May 6, 2026
* refactor: migrate user preferences from SQLite to config.json

Move portable user preferences (theme, font, editor width, etc.) from
SQLite-only storage to <vault>/.memry/config.json as the source of truth.
SQLite becomes a read cache for fast IPC performance.

Key changes:
- VaultPreferences Zod schema + readPreferences/writePreferences helpers
- SET_GENERAL_SETTINGS and SET_EDITOR_SETTINGS write config.json first,
  then update SQLite cache
- Vault open flow migrates: if config.json has preferences, use them;
  if missing, seed from SQLite (one-time migration)
- settingsHandler.applyUpsert now propagates merged sync data to
  config.json, updates SQLite cache, and broadcasts CHANGED events
  (fixes the synced_settings → general key gap)
- Machine-local settings (startOnBoot, onboardingCompleted, etc.) stay
  in SQLite only

68 new/updated tests across 5 test files, all passing.

* docs: add settings config.json migration changelog entry

* fix: resolve type errors in settings-cache for CI typecheck

Use schema/index import for DrizzleDb type compatibility and fix
editor seed object typing in migrateSettingsToConfig.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant