Skip to content

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

@hideyukiMORI

Description

@hideyukiMORI

Source: FT17 (#417 / PR #418). ADR-0009 の実装本体。

やること (1 PR)

Code

  • `class/xion/SchemaDiffer.php` 新規 (pure-static、DB-agnostic)
    • `diff(array $live, array $definition, string $driver): array`
    • Returns: { newTables, newColumns, warnings, inSync }
  • `cli/schemaDiff.php` 新規 (PDO + stdout/stderr wrapper)
    • introspectMysql (INFORMATION_SCHEMA.COLUMNS)
    • introspectSqlite (PRAGMA table_info)
    • stdout = 適用すべき SQL のみ、stderr = annotation + warning
  • `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

  • ADR-0009 の "Implementation tracking" section に PR # を cross-link

受け入れ条件

  • composer test 138/138 (128 → 138)
  • composer analyze (Phan) exit 0
  • composer format:check exit 0
  • live: php cli/schemaDiff.php --dsn=mysql:... で in-sync 出力
  • live: DROP COLUMN 後の diff CLI が ALTER TABLE ADD COLUMN を 1 行出力
  • live: DROP TABLE 後の diff CLI が CREATE TABLE 出力
  • live: 追加列をした live DB に対して stderr warning + stdout 空

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions