refactor: settings に _schemaVersion を導入し migration を versioned array 化 (#208)#230
Merged
Conversation
#208) - `src/lib/store-migration.ts` を新設し、`MIGRATIONS` 配列・`LATEST_SCHEMA_VERSION`・ `applyMigrations()` で settings.json の schema 変換を versioned array で表現する - 既存の inline if-else 形式 (theme → themePreference 変換) を MIGRATIONS[0] に移植し、 store.ts の `loadSettings()` 冒頭で `applyMigrations()` を 1 回呼ぶ形にリファクタ - 今後の migration 追加は MIGRATIONS に 1 entry 追加で完結し、loadSettings に分岐が増えない - `_schemaVersion` は settings.json 上にのみ書かれ、`AppSettings` interface には surface しない (storage 内部の concern を public interface に leak しない) - unit test (`src/lib/store-migration.test.ts` 9 ケース) と e2e (`e2e/electron/settings-migration.electron.spec.ts` に _schemaVersion 書き込み verify と skip シナリオを追加) を追加 - `docs/specification.md` に Settings の追加・移行フロー (型 / DEFAULTS / migration / test の 4 ステップ + 判断ルール) を明記 Closes #208 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ymnao
added a commit
that referenced
this pull request
Jun 26, 2026
- `CHANGELOG.md` に v0.6.0 セクションを追加 - Internal: #206 → #229 (AppLayout useShallow), #208 → #230 (settings _schemaVersion + MIGRATIONS), #207 → #231 (2 モード e2e 振り分け + ADR-0009 集約), #225 → #232 (onNavigate wikilink target), #226 → #233 (useCollapseToggle hook), #228 → #234 (createScanAction factory), #227 → #235 (producer-side lineContent trim) - `package.json` の `version` を `0.5.0` → `0.6.0` - HANDOFF の規約通り、本 commit では `pnpm <script>` を呼ばない (lockfile / node_modules には触れない)
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.
概要
settings.json の schema migration を versioned array で表現するリファクタリング (#208)。
従来
loadSettings()内に inline if-else で記述されていた legacytheme→themePreference変換を
src/lib/store-migration.tsのMIGRATIONS配列に移植し、_schemaVersionで適用済み migration を追跡する形に切り替えた。次の migration 追加は MIGRATIONS に 1 entry
追加で完結し、
loadSettingsに分岐が増えない。関連 Issue
Closes #208
移行 Stage
該当なし — Tauri purge 後の継続的なアーキテクチャ refactor (v0.6.0 milestone Tier 1)。
変更内容
src/lib/store-migration.ts新設:MIGRATIONS配列 +applyMigrations()+LATEST_SCHEMA_VERSIONsrc/lib/store.ts:loadSettings()冒頭で migration 適用、inline theme 変換コードを削除_schemaVersionは settings.json 上にのみ書かれ、AppSettingsinterface には surface しない(storage 内部の concern を public interface に leak しない — /simplify Altitude F1 採用)
src/lib/store-migration.test.ts新設: 9 ケース (構造 / fresh / migration / skip / 不正値)src/lib/store.test.ts: migration skip テスト追加、stateful mock で migration の disk 効果を verifye2e/electron/settings-migration.electron.spec.ts:_schemaVersion=1書き込み verify + skip シナリオdocs/specification.md: Settings の追加・移行フロー (型 / DEFAULTS / migration / test の 4 ステップ + 判断ルール) を明記設計判断: issue 提案からの逸脱
issue の提案は snapshot-based な
migrateSettings(raw)pure function だったが、settings IPC がkey-level (
settings:get/set/delete/save、snapshot API なし) であるため、現状の I/O 形と整合しない。代わりに
MigrationContextを介した key-level の副作用として記述する形を採用した(
run(ctx)内でctx.get/set/deleteを使う)。本旨「array 1 entry 追加で新 migration が記述可能」は満たしている。
/simplify で skip した correctness 領域の指摘 (別途検討対象)
quality 改善の /simplify では scope 外として skip したが、correctness 観点で別途検討すべき点が
2 件:
loadSettings()の top-leveltry { ... } catch {}がapplyMigrationsの書き込み失敗を{ ...DEFAULTS }に縮退させる挙動 — migration が theme delete までは成功したが_schemaVersionset で IPC エラーになった場合、disk は中途半端な状態で残り、次回起動でmigration が再実行される。idempotent なら問題ないが、framework の保証としては弱い。
run(ctx)の書き込み群 +_schemaVersionset) で非 atomic。crash 時の整合は idempotent run に依存。
いずれも現状 (migration 1 件のみ、すべて idempotent) では実害なし。次回 non-idempotent な
migration を追加する前に別 issue で検討する。
動作確認
settings-migration.electron.spec.tsの 3 ケースが pass)~/Library/Application Support/scripta-next/settings.jsonに_schemaVersion: 1が刻まれるthemeキーが残っている disk から起動するとthemePreferenceに変換されthemeが削除されるスクリーンショット
UI 変更なし。