Skip to content

fix(schema)!: index schema metadata by table name - #1190

Merged
Tigrov merged 2 commits into
yiisoft:masterfrom
KalimeroMK:fix-1176-schema-metadata-indexed-by-table-name
Aug 2, 2026
Merged

Tigrov merged 2 commits into
yiisoft:masterfrom
KalimeroMK:fix-1176-schema-metadata-indexed-by-table-name

Conversation

@KalimeroMK

Copy link
Copy Markdown
Contributor

getSchemaMetadata() appended per-table results with $metadata[], discarding which table each entry belonged to. Callers of getSchemaForeignKeys() received a flat list of ForeignKey[] groups with no way to map them back to their owning table.

Also corrects @return annotations that documented ForeignKey[] and Index[] for values that have always been arrays of arrays, and loads fixtures in the schema tests, which previously passed vacuously against an empty database.

BREAKING CHANGE: getSchemaChecks(), getSchemaDefaultValues(), getSchemaForeignKeys(), getSchemaIndexes(), getSchemaPrimaryKeys(), getSchemaUniques() and getTableSchemas() return arrays keyed by table name. Iterating with foreach is unaffected; code relying on sequential integer offsets must be updated.

Closes #1176

Q A
Is bugfix? ✔️/❌
New feature? ✔️/❌
Breaks BC? ✔️/❌
Tests pass? ✔️/❌
Fixed issues comma-separated list of tickets # fixed by the PR, if any

getSchemaMetadata() appended per-table results with $metadata[],
discarding which table each entry belonged to. Callers of
getSchemaForeignKeys() received a flat list of ForeignKey[] groups
with no way to map them back to their owning table.

Also corrects @return annotations that documented ForeignKey[] and
Index[] for values that have always been arrays of arrays, and loads
fixtures in the schema tests, which previously passed vacuously
against an empty database.

BREAKING CHANGE: getSchemaChecks(), getSchemaDefaultValues(),
getSchemaForeignKeys(), getSchemaIndexes(), getSchemaPrimaryKeys(),
getSchemaUniques() and getTableSchemas() return arrays keyed by table
name. Iterating with foreach is unaffected; code relying on
sequential integer offsets must be updated.

Closes yiisoft#1176
@codecov

codecov Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.62%. Comparing base (6ca9de5) to head (d1486c5).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1190   +/-   ##
=========================================
  Coverage     98.62%   98.62%           
  Complexity     1645     1645           
=========================================
  Files           120      120           
  Lines          4288     4288           
=========================================
  Hits           4229     4229           
  Misses           59       59           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes schema metadata aggregation so per-table schema results are returned keyed by table name (instead of a flat list that loses ownership information), addressing #1176 and making the affected APIs reliably mappable back to their tables.

Changes:

  • Change AbstractSchema::getSchemaMetadata() to index results by table name rather than appending to a numeric array.
  • Update PHPDoc / Psalm annotations for schema/constraint APIs to reflect the keyed-by-table return shape (including primary keys omitting tables without PKs).
  • Update tests to expect keyed results and ensure fixtures are loaded so schema tests don’t pass against an empty database.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/Db/Schema/SchemaTest.php Updates unit-level schema tests to assert results are keyed by owning table name and FK metadata remains accessible.
tests/Common/CommonSchemaTest.php Updates integration-style schema tests to load fixtures and iterate schema metadata as tableName => items.
src/Schema/SchemaInterface.php Documents getTableSchemas() as returning an array indexed by table name (Psalm-typed).
src/Schema/AbstractSchema.php Implements the core behavior change: schema metadata is aggregated as [$tableName => $tableMetadata].
src/Constraint/ConstraintSchemaInterface.php Corrects return annotations to reflect arrays-of-arrays keyed by table name (and PKs as array<string, Index>).
CHANGELOG.md Adds a changelog entry documenting the behavioral change and affected methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Tigrov Tigrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Comment thread src/Schema/AbstractSchema.php Resolved
Replace array<string, mixed> with the concrete union, matching the
@return annotation directly above it.

Refs yiisoft#1190
@Tigrov
Tigrov merged commit 2228817 into yiisoft:master Aug 2, 2026
81 checks passed
@Tigrov

Tigrov commented Aug 2, 2026

Copy link
Copy Markdown
Member

Thanks 👍

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.

getSchemaForeignKeys() does not return related table names

6 participants