Skip to content

Conversation

@taka-oyama
Copy link
Collaborator

@taka-oyama taka-oyama commented May 19, 2025

Merging 8.x fixes and also fix laravel 12 specific errors in 62bc09e.

Summary by CodeRabbit

  • New Features
    • Enhanced schema metadata retrieval to provide detailed information for tables, columns, indexes, and foreign keys.
  • Bug Fixes
    • Improved handling of nullable columns and default values in schema processing.
  • Refactor
    • Standardized data processing by using object properties and expanded returned metadata structures.
  • Tests
    • Added and updated tests to verify detailed column and foreign key metadata.
  • Chores
    • Updated static analysis configuration and Dockerfile for improved stability and compatibility.

@taka-oyama taka-oyama requested a review from a team May 19, 2025 01:00
@taka-oyama taka-oyama self-assigned this May 19, 2025
@taka-oyama taka-oyama added the bug Something isn't working label May 19, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 19, 2025

Walkthrough

The changes update schema metadata handling in the codebase. Metadata extraction methods for tables, columns, indexes, and foreign keys are refactored to use object properties and return richer, more structured arrays. SQL grammar methods are expanded for detailed metadata queries. Tests are updated and extended to reflect these changes.

Changes

File(s) Change Summary
Dockerfile Sets protobuf PECL extension version to 4.30.2 using pecl_mt_install.
phpstan.neon Adds two new PHPStan ignore rules for specific closure argument errors in src/Schema/Builder.php.
src/Query/Processor.php Refactors metadata processing methods to use object properties, adds processTables, enriches returned arrays for tables, columns, indexes, and foreign keys.
src/Schema/Builder.php Removes getTables method, updates index and foreign key handling, improves type annotations, and removes an unused comment.
src/Schema/Grammar.php Expands compileTables to include table_schema, adds new compileColumns, and rewrites compileForeignKeys to use multi-table joins for detailed metadata. Removes duplicate compileColumns.
tests/Schema/BuilderTestLast.php Updates test_getTables to check full metadata, splits test_getColumns into two specific tests, and adds a new test_getForeignKeys.

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 62bc09e and 2c548ca.

📒 Files selected for processing (1)
  • tests/Schema/BuilderTestLast.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Schema/BuilderTestLast.php
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run-PHPUnit
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Comment on lines +9 to +19
-
message: '#^Closure invoked with 2 parameters, 3 required\.$#'
identifier: arguments.count
count: 1
path: src/Schema/Builder.php

-
message: '#^Parameter \#2 of closure expects Closure, Closure\|null given\.$#'
identifier: argument.type
count: 1
path: src/Schema/Builder.php
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This error will be fixed with this PR. #279

Comment on lines +85 to +95
/** @var list<array{
* name: string,
* schema: string|null,
* schema_qualified_name: string,
* size: int|null,
* comment: string|null,
* collation: string|null,
* engine: string|null,
* parent: string|null
* }> $tables
*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

adds parent: string|null to shape.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (2)
src/Schema/Grammar.php (1)

69-82: Missing schema filter & unused $schema argument in compileColumns()

Just like compileTables(), the first parameter is never referenced.
Either:

  • remove the parameter (breaking change – adjust callers), or
  • add a predicate: and table_schema = ….

This prevents future confusion and eliminates phpstan’s warning.

src/Query/Processor.php (1)

171-183: Guard against empty delimiter fallout

Once compileForeignKeys() is fixed (see previous comment) the explode(',', …) logic works.
If not fixed, this returns an array with one long element. Consider defensive code:

'columns'         => $result->columns === '' ? [] : explode(',', $result->columns),
'foreign_columns' => $result->foreign_columns === '' ? [] : explode(',', $result->foreign_columns),

Not critical after the grammar patch, but keeps the processor resilient.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between bd0adbe and 62bc09e.

📒 Files selected for processing (6)
  • Dockerfile (1 hunks)
  • phpstan.neon (1 hunks)
  • src/Query/Processor.php (2 hunks)
  • src/Schema/Builder.php (3 hunks)
  • src/Schema/Grammar.php (2 hunks)
  • tests/Schema/BuilderTestLast.php (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run-PHPUnit
🔇 Additional comments (9)
Dockerfile (1)

37-37: Version pinning for protobuf PECL extension

Pinning the protobuf extension to a specific version (4.30.2) is a good practice for reproducible builds. This ensures consistent behavior across development and production environments.

src/Schema/Builder.php (4)

62-62: Good use of more specific method

Changing from getIndexes to getIndexListing is appropriate since you only need the index names, not the full metadata objects. This should improve performance slightly since less data needs to be processed.


85-95: Well-documented table structure

The detailed PHPDoc type annotation for the $tables variable provides excellent documentation about the expected structure of each table entry. This improves code readability and helps with static analysis.


133-133: Appropriate parameter simplification

Changed from passing the entire foreign key array to only passing the name string when calling dropForeign. This is more efficient and aligns with how the method is typically used.


96-96:

✅ Verification successful

Missing getTables method

Line 96 calls $this->getTables() but no implementation of this method is present in the file. Based on PHPStan ignores and test modifications, this appears to be an issue.


🏁 Script executed:

#!/bin/bash
# Check if getTables method exists in this class or parent classes
rg -A 3 "function getTables" src/

Length of output: 35


🏁 Script executed:

#!/bin/bash
# Search for getTables declaration across entire repo
rg -n "function getTables" .

# Show the top of src/Schema/Builder.php to see namespace and inheritance
head -n 30 src/Schema/Builder.php

# Locate the class declaration to check for parent class or traits
rg -n "class .*Builder" -n src/Schema/Builder.php

Length of output: 1044


🌐 Web query:

Does the Laravel Illuminate\\Database\\Schema\\Builder class define a getTables method?

💡 Result:

The Illuminate\Database\Schema\Builder class in Laravel does define a getTables() method. This method retrieves the tables that belong to the database as an array[7].

Here is a summary of related methods in the class:

  • getTables() — Gets the tables that belong to the database[7].
  • getTableListing() — Gets the names of the tables in the database[1][7].
  • There’s also a deprecated getAllTables() method[7].

So, if you are looking to obtain the list of tables in your database via the schema builder, getTables() is indeed available as a method on this class[7].

Citations:


Inherited getTables method present

The call to $this->getTables() is valid: it’s defined on the parent class Illuminate\Database\Schema\Builder, so no implementation is needed in your subclass.

No changes required.

tests/Schema/BuilderTestLast.php (4)

216-226: Updated test for table structure

The test has been properly updated to verify the detailed structure of table metadata, including schema, parent, size, comment, collation, and engine properties.


229-250: Good test coverage for nullable columns

The new test provides specific coverage for nullable columns with primary keys, validating all the metadata properties including type, collation, and default values.


252-273: Well-structured test for columns with defaults

This test properly verifies columns with default values, ensuring that the default value is correctly represented in the column metadata.


335-363: Comprehensive foreign key metadata test

The new test for foreign keys thoroughly validates all aspects of foreign key metadata, including name, columns, referenced table and columns, and update/delete actions.

@taka-oyama taka-oyama merged commit 07f066c into master May 21, 2025
1 check passed
@taka-oyama taka-oyama deleted the fix/schema-meta-data branch May 21, 2025 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working waiting for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants