feat(schema): SchemaDiffer に add-index path を追加する (#421, FT17 F-5)#424
Merged
Conversation
FT17 (#417) で deferred とした最後の ADR-0009 scope 項目を消化。 SchemaDefinition の indexes キーに新規追加した index を cli/schemaDiff.php が "CREATE INDEX" として emit するように。 ### SchemaDiffer - diff() 戻り値に newIndexes 追加 (newColumns と同 shape) - inSync は newTables + newColumns + newIndexes 全部空のとき true - 既存 live のみの index → warning (drop must be hand-written) - createIndexSql() は MySQL / SQLite 共通 syntax (両 driver で動く) ### CLI 拡張 - introspectMysql に INFORMATION_SCHEMA.STATISTICS index 列挙を追加 - PRIMARY 除外 + NON_UNIQUE=1 フィルタ - UNIQUE constraint 由来 index は \`unique\` キー管理なので除外 - introspectSqlite に PRAGMA index_list + PRAGMA index_info を追加 - sqlite_autoindex_* 除外 + unique=1 除外 (同じ理由) - stdout 出力に "new index: <name> on <table>" + CREATE INDEX SQL ### Tests (4 cases追加 → 142/142) - testNewIndexEmitsCreateIndex - testCompositeIndexEmitsBothColumns (multi-column index) - testExtraLiveIndexEmitsWarningNotSql - testIndexInSyncDoesNotEmitDuplicate ### Live verification - 既存 schema: in-sync (UNIQUE false-positive 解消、これは UNIQUE filter が無いと users_user_id_unique を誤検出していた hidden bug) - DROP INDEX todos_user_id_index 後の diff → CREATE INDEX 出力 - 出力を mysql に pipe → 復元 → in-sync ### ADR-0009 scope 完了 ADR-0009 が当初指定した initial scope (Add column / Add table / **Add index**) が本 PR で揃った。残るは drop / type-change / rename / constraint changes — それらは ADR の destructive-op rule で warning-only 扱い、operator hand-write。 Closes #421. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
FT17 (#417) で deferred とした最後の ADR-0009 initial-scope 項目 (Add index) を消化。
SchemaDiffer
CLI 拡張
Hidden bug 解消
UNIQUE filter なしのとき、CREATE TABLE の `unique` 由来 index (`users_user_id_unique`) が "live にあるが SchemaDefinition の indexes に無い" と誤検出 → false warning を毎回出していた。UNIQUE filter で解消。
Live verification
Tests (+4, 142/142)
`SchemaDifferTest`:
ADR-0009 scope 完了
initial scope (Add column / Add table / Add index) 全揃い。Closes #421.
Test plan
Closes #421.