Skip to content

Conversation

@taka-oyama
Copy link
Collaborator

Closes #282

@taka-oyama taka-oyama requested a review from a team July 15, 2025 07:24
@taka-oyama taka-oyama self-assigned this Jul 15, 2025
@taka-oyama taka-oyama added the enhancement New feature or request label Jul 15, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 15, 2025

Walkthrough

The changes introduce comprehensive support for named schemas in the schema management and introspection components. In the schema builder, methods are updated to handle schema-qualified table names throughout table, index, and foreign key operations. SQL grammar methods are enhanced to support schema filtering, array schema inputs, and consistent identifier quoting. The blueprint class now generates index names with schema awareness. The test suite is expanded with new methods to verify correct behavior for named schemas, including creation, listing, column, index, and foreign key retrieval. Emulator setup is improved with authentication caching and polling adjustments.

Assessment against linked issues

Objective Addressed Explanation
Add support for named schemas in schema operations (creation, listing, etc.) (#282)
Ensure schema-qualified table, index, and foreign key handling in builder and grammar (#282)
Generate index names with schema awareness (#282)
Expand tests to cover named schema scenarios for all schema operations (#282)

Suggested labels

waiting for review


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37772cf and a0df49f.

📒 Files selected for processing (5)
  • src/Schema/Blueprint.php (1 hunks)
  • src/Schema/Builder.php (4 hunks)
  • src/Schema/Grammar.php (4 hunks)
  • tests/Schema/BuilderTestLast.php (7 hunks)
  • tests/TestCase.php (3 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: taka-oyama
PR: colopl/laravel-spanner#243
File: tests/Schema/BlueprintTest.php:697-698
Timestamp: 2024-12-16T09:35:32.707Z
Learning: In `tests/Schema/BlueprintTest.php`, the argument `'bit_reversed_positive start counter with 2'` passed to the `generatedAs` method is correct syntax for defining identity columns.
tests/TestCase.php (1)
Learnt from: taka-oyama
PR: colopl/laravel-spanner#243
File: tests/Schema/BlueprintTest.php:697-698
Timestamp: 2024-12-16T09:35:32.707Z
Learning: In `tests/Schema/BlueprintTest.php`, the argument `'bit_reversed_positive start counter with 2'` passed to the `generatedAs` method is correct syntax for defining identity columns.
src/Schema/Blueprint.php (1)
Learnt from: taka-oyama
PR: colopl/laravel-spanner#243
File: tests/Schema/BlueprintTest.php:697-698
Timestamp: 2024-12-16T09:35:32.707Z
Learning: In `tests/Schema/BlueprintTest.php`, the argument `'bit_reversed_positive start counter with 2'` passed to the `generatedAs` method is correct syntax for defining identity columns.
src/Schema/Grammar.php (1)
Learnt from: taka-oyama
PR: colopl/laravel-spanner#243
File: tests/Schema/BlueprintTest.php:697-698
Timestamp: 2024-12-16T09:35:32.707Z
Learning: In `tests/Schema/BlueprintTest.php`, the argument `'bit_reversed_positive start counter with 2'` passed to the `generatedAs` method is correct syntax for defining identity columns.
tests/Schema/BuilderTestLast.php (1)
Learnt from: taka-oyama
PR: colopl/laravel-spanner#243
File: tests/Schema/BlueprintTest.php:697-698
Timestamp: 2024-12-16T09:35:32.707Z
Learning: In `tests/Schema/BlueprintTest.php`, the argument `'bit_reversed_positive start counter with 2'` passed to the `generatedAs` method is correct syntax for defining identity columns.
🧬 Code Graph Analysis (2)
src/Schema/Builder.php (1)
src/Connection.php (1)
  • statement (322-340)
src/Schema/Blueprint.php (1)
src/Connection.php (1)
  • getSchemaBuilder (222-229)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run-PHPUnit
🔇 Additional comments (12)
src/Schema/Blueprint.php (1)

491-512: LGTM! Well-implemented schema-aware index naming.

The createIndexName method correctly handles schema-qualified index names by:

  • Parsing schema and table names using the schema builder
  • Respecting the prefix_indexes configuration
  • Only prefixing non-foreign key indexes with schema names
  • Properly formatting the index name with underscores

This implementation aligns well with the broader schema support added throughout the codebase.

tests/TestCase.php (3)

32-32: LGTM! Appropriate imports for new functionality.

The added imports support the new generateNamedSchemaName method and authentication caching enhancements.

Also applies to: 34-34


69-72: LGTM! Useful helper method for schema testing.

The generateNamedSchemaName method provides a simple way to create unique schema names for testing, using a timestamp and random string to ensure uniqueness.


135-140: LGTM! Good emulator setup improvements.

The changes enhance the emulator setup with:

  • Authentication caching using FilesystemAdapter for better performance
  • Reduced polling interval (0.001 seconds) for faster instance creation during tests

These improvements should make tests more efficient.

Also applies to: 144-146

src/Schema/Builder.php (2)

63-72: LGTM! Clean schema creation implementation.

The createNamedSchema method properly wraps the schema name using the grammar and executes the DDL statement through the connection. This follows the established pattern for schema operations.


141-141: LGTM! Comprehensive schema-qualified name handling.

The modifications to dropAllTables properly implement schema support by:

  • Using schema_qualified_name consistently for table indexing and operations
  • Handling schema-qualified names for foreign key and index operations
  • Properly prefixing index names with schema when present

This ensures that all table operations work correctly with named schemas.

Also applies to: 164-166, 178-188

src/Schema/Grammar.php (2)

43-63: LGTM! Excellent schema filtering implementation.

The compileTables method now handles schema filtering dynamically:

  • Supports array of schemas with IN clause
  • Handles single schema with equality condition
  • Defaults to no filtering when schema is null
  • Consistent backtick quoting and proper ordering

This flexible approach supports various schema querying scenarios.


66-83: LGTM! Consistent schema support across introspection methods.

The updates to compileColumns, compileIndexes, and compileForeignKeys provide:

  • Consistent schema filtering using the $schema parameter
  • Proper backtick quoting for identifiers
  • Appropriate GROUP BY clauses where needed
  • Unified handling of schema information

This ensures all schema introspection queries work correctly with named schemas.

Also applies to: 86-104, 106-129

tests/Schema/BuilderTestLast.php (4)

206-308: LGTM! Comprehensive schema testing coverage.

The expanded getTables tests properly verify:

  • Default schema behavior with proper null schema values
  • Named schema behavior with correct schema-qualified names
  • Combined scenarios testing both default and named schemas
  • Proper use of the new createNamedSchema method

This thorough testing ensures the schema functionality works correctly across all scenarios.


356-380: LGTM! Well-structured schema-aware column and table listing tests.

The tests for getColumns and getTableListing with named schemas properly:

  • Test schema-qualified table names
  • Verify correct column metadata retrieval
  • Handle both qualified and unqualified name scenarios
  • Use appropriate test data setup

These tests ensure schema-qualified operations work correctly.

Also applies to: 382-422


424-493: LGTM! Complete index testing for named schemas.

The expanded index tests (getIndexes and getIndexListing) properly verify:

  • Index creation and retrieval in named schemas
  • Proper index naming conventions
  • Both default and named schema scenarios
  • Correct metadata structure

This ensures index operations work correctly with schema-qualified names.

Also applies to: 512-531


563-596: LGTM! Thorough foreign key testing for named schemas.

The getForeignKeys test for named schemas properly validates:

  • Foreign key creation between schema-qualified tables
  • Correct foreign key metadata with schema information
  • Proper handling of schema-qualified references
  • Expected foreign key constraint naming

This ensures foreign key operations work correctly across named schemas.

✨ 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.

@taka-oyama taka-oyama marked this pull request as ready for review July 15, 2025 08:34
Copilot AI review requested due to automatic review settings July 15, 2025 08:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for named schemas in Spanner by extending schema building, grammar queries, and tests.

  • Introduces generateNamedSchemaName and configures emulator client in TestCase.php
  • Adds comprehensive tests for named-schema flows in BuilderTestLast.php
  • Updates Grammar.php, Builder.php, and Blueprint.php to handle schema-qualified identifiers and index naming

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/TestCase.php Added generateNamedSchemaName, Str import, authCache, and polling options for emulator setup
tests/Schema/BuilderTestLast.php Added tests covering named-schema support for tables, columns, indexes, foreign keys, and listings
src/Schema/Grammar.php Quoted identifiers and added schema filtering to compile methods
src/Schema/Builder.php Introduced createNamedSchema and updated dropAllTables to use schema-qualified names
src/Schema/Blueprint.php Overrode createIndexName to include schema prefix when generating index names
Comments suppressed due to low confidence (2)

tests/Schema/BuilderTestLast.php:356

  • [nitpick] The test name suggests only default schema listing but it actually verifies both default and named schema results. Consider renaming the test to reflect that it covers both cases (e.g., test_getTableListing__for_default_and_named_schemas).
    public function test_getColumns__for_named_schema_table(): void

tests/TestCase.php:145

  • [nitpick] Using a pollingIntervalSeconds of 0.001 may be cast to 0 and result in a busy-wait loop or CPU spike. Consider using an integer or supported precision (e.g., 1 second) or verify that fractional intervals are honored by the emulator client.
                'pollingIntervalSeconds' => 0.001,

@taka-oyama taka-oyama merged commit e01b70e into master Jul 22, 2025
2 checks passed
@taka-oyama taka-oyama deleted the feature/named-schema branch July 22, 2025 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Named Schema Support

2 participants