GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor: settings に _schemaVersion を導入し migration を versioned array 化 · Issue #208 · ymnao/scripta

refactor: settings に _schemaVersion を導入し migration を versioned array 化 #208

New issue
Copy link
New issue
Copy link
Closed
#230
Closed
refactor: settings に _schemaVersion を導入し migration を versioned array 化#208
#230
Copy link
Labels
enhancementNew feature or request
Milestone
v0.6.0

Description

@ymnao
ymnao
opened on Jun 21, 2026
Issue body actions

背景

セッション 26 の C 軸 (アーキテクチャ) 探索で、src/lib/store.ts:61-225 の settings migration が inline if-else で記述されており、schema version 管理がない ことを同定した。

現状の migration ロジック:

  • loadSettings() 内で legacy key theme → themePreference の変換を hard-code
  • 各フィールドで typeof チェック + 値域チェック → DEFAULTS へ fall through
  • settings.json 自体に _schemaVersion フィールドなし

これは現在の 1 つの migration だけなら問題ないが、次の migration (例: fontSize: number → fontSize: { value: 14, unit: "px" }) が来た時に同じ if-else chain を追記するしかなく、工数が線形に増加する。

推奨パターンとの差分

設定マイグレーションの standard pattern:

type Migration = { from: number; to: number; run: (data: unknown) => unknown };

const MIGRATIONS: Migration[] = [
  { from: 0, to: 1, run: (data) => ({ ...data, themePreference: data.theme, theme: undefined }) },
  // 次の migration はここに追記
];

function migrateSettings(raw: unknown): AppSettings {
  let current = raw;
  const version = (raw as { _schemaVersion?: number })._schemaVersion ?? 0;
  for (const m of MIGRATIONS.filter((m) => m.from >= version)) {
    current = m.run(current);
  }
  return { ...validate(current), _schemaVersion: latestVersion };
}

これにより:

  • 各 migration が独立した関数として記述・テスト可能
  • migration の追加コストが「array に 1 entry 追加」で済む
  • 古いバージョンから新しいバージョンへの全 path を 1 関数で表現

改善案

1. AppSettings 型に _schemaVersion: number を追加

2. src/lib/store-migration.ts (新規) に migration 配列と適用関数を切り出し

src/lib/store.ts の loadSettings() は migration 適用後の validation のみ担当。

3. 既存 migration (theme → themePreference) を MIGRATIONS[0] として移植

4. unit test を追加

  • loadSettings({ theme: "light", _schemaVersion: undefined }) → 旧形式が themePreference: "light" + _schemaVersion: 1 に変換される
  • loadSettings({ themePreference: "dark", _schemaVersion: 1 }) → 既に最新版なので migration スキップ

5. e2e (settings-migration.electron.spec.ts) で同じシナリオを実 IPC で検証

完了条件

  • AppSettings 型に _schemaVersion フィールド追加
  • src/lib/store-migration.ts に migration 配列を切り出し
  • 既存 theme → themePreference migration を新形式に移植
  • unit test 追加 (旧形式 / 最新版 / 中間バージョン 3 ケース)
  • settings-migration.electron.spec.ts 既存テスト pass
  • HANDOFF or CONTRIBUTING に「新フィールド追加フロー」を明記 (型 → DEFAULTS → migration → test の 4 ステップ)

実害度

中 (次の migration で工数発生が確定するため、先送りの損失が増え続ける)

関連

  • セッション 26 C 軸探索 (HANDOFF.md セッション 26)
  • e2e/electron/settings-migration.electron.spec.ts (既存 migration テスト)

Activity

  1. ymnao
    added this to the v0.6.0 milestone on Jun 21, 2026
  2. ymnao
    added
    enhancementNew feature or request
    on Jun 21, 2026
  3. ymnao
    added a commit that references this issue on Jun 24, 2026

    refactor: settings に _schemaVersion を導入し migration を versioned array 化 (

    68881b1
  4. ymnao
    closed this as completedin #230on Jun 24, 2026
  5. ymnao
    added a commit that references this issue on Jun 26, 2026

    chore: v0.6.0 リリース準備 (#242)

    ce98367
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      • v0.6.0No due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.