Skip to content

feat(schema): SchemaDiffer + cli/schemaDiff.php + composer schema:diff (#419, ADR-0009 impl)#422

Merged
hideyukiMORI merged 1 commit into
mainfrom
feat/419-schema-diff-cli
May 22, 2026
Merged

feat(schema): SchemaDiffer + cli/schemaDiff.php + composer schema:diff (#419, ADR-0009 impl)#422
hideyukiMORI merged 1 commit into
mainfrom
feat/419-schema-diff-cli

Conversation

@hideyukiMORI
Copy link
Copy Markdown
Owner

ADR-0009 (#416) で採用した Option C を実装。FT17 (#417 / PR #418) で trial 検証済み、本 PR で framework に port。

Code

  • `class/xion/SchemaDiffer.php` 新規 (pure-static、DB-agnostic)
  • `cli/schemaDiff.php` 新規 (MySQL + SQLite 両 driver サポート、stdout = SQL、stderr = annotation)
  • `SchemaCompiler` 4 helper を private → public 化 (mysqlCreateTable / sqliteCreateTable / mysqlColumn / sqliteColumn)
  • `composer schema:diff` alias

Tests

`tests/Unit/Xion/SchemaDifferTest.php` 10 cases (in-sync / new-table / new-column / bool default / extra-column warning / extra-table warning / multi-warnings / inSync flag)。

Out of scope

ADR-0009 cross-link

`docs/adr/0009-schema-migration-story.md` の "Implementation tracking" section に本 PR + F-5 follow-up を明記。

Test plan

  • composer test 138/138 (128 → 138)
  • composer test:http 24/24 (1 expected skip)
  • composer analyze (Phan) exit 0
  • composer format:check exit 0
  • `composer schema:diff -- --dsn=mysql:...` で live in-sync / column-drop / table-drop の 3 scenario green

Closes #419.

#419, ADR-0009 impl)

ADR-0009 (#416) で Option C 採用、FT17 (#417) で実装した schema-diff
CLI を framework に port。商用 feasibility report (#401) の "最大の実務
懸念" (migration 機構の欠如) に対する operator-applied resolution。

### Code

- class/xion/SchemaDiffer.php 新規 (pure-static、DB-agnostic)
  - diff(\$live, \$definition, \$driver): array{newTables, newColumns,
    warnings, inSync}
- cli/schemaDiff.php 新規 (PDO + stdout/stderr 分離 CLI)
  - introspectMysql / introspectSqlite で driver 自動検出
  - stdout = applied SQL only、stderr = annotation + warning
  - --dsn / --user / --pass / --help
- class/xion/SchemaCompiler.php
  - 4 helper を private → public (mysqlCreateTable / sqliteCreateTable
    / mysqlColumn / sqliteColumn)
- composer.json に "schema:diff" alias

### Tests

tests/Unit/Xion/SchemaDifferTest.php 10 cases:
- in-sync / new-table (MySQL+SQLite) / new-column (MySQL+SQLite) /
  bool default propagation / extra-column warning / extra-table warning /
  multi-warnings accumulate / inSync flag

### ADR cross-link

docs/adr/0009-schema-migration-story.md の "Implementation tracking"
section を更新: 本 PR # と F-5 follow-up issue 番号を明記。

### Out of scope (per ADR-0009)

- Drop / type-change / rename / constraint-change → warning のみ、SQL
  emit しない (operator hand-write)
- Auto-apply (operator が常に実行する flow を維持)
- Add-index path (本 PR に含めない、別 follow-up #421 で)

### Verification

- composer test 138/138 (128 → 138、+10)
- composer test:http 24/24 (1 expected skip)
- composer analyze (Phan) exit 0
- composer format:check exit 0
- composer schema:diff -- --dsn=mysql:host=... で in-sync 確認、column
  drop → ALTER TABLE 出力、table drop → CREATE TABLE 出力 を live verify

Closes #419.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@hideyukiMORI hideyukiMORI merged commit 61c2f96 into main May 22, 2026
2 checks passed
@hideyukiMORI hideyukiMORI deleted the feat/419-schema-diff-cli branch May 22, 2026 16:57
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.

FT17 feat: SchemaDiffer + cli/schemaDiff.php + SchemaCompiler promote + composer schema:diff (#417)

1 participant