Skip to content

Conversation

@taka-oyama
Copy link
Collaborator

@taka-oyama taka-oyama commented Nov 6, 2024

Its not documented, but it's supported.
Probably because its used to define TOKENLIST.

Summary by CodeRabbit

  • New Features
    • Introduced support for invisible columns in database schemas.
    • Added support for change streams and snapshot queries.
    • Enhanced commit options configuration.
  • Bug Fixes
    • Resolved issues with schema changes being applied twice.
    • Addressed PHPStan errors and updated method signatures for compatibility.
  • Tests
    • Added tests for creating tables with invisible columns and change streams, and refined existing tests for row deletion policies.

@taka-oyama taka-oyama added enhancement New feature or request waiting for review labels Nov 6, 2024
@taka-oyama taka-oyama requested a review from a team November 6, 2024 06:49
@taka-oyama taka-oyama self-assigned this Nov 6, 2024
@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2024

Walkthrough

This pull request introduces significant updates to the changelog and the Grammar and BlueprintTest classes. It adds support for invisible columns, change streams, and snapshot queries, while deprecating certain methods. The Grammar class is enhanced to handle invisible columns through a new modifier and method. Testing coverage is improved with new tests for invisible columns, row deletion policies, and change streams, ensuring the correct generation of SQL statements.

Changes

File Change Summary
CHANGELOG.md Updated to include new features (invisible columns, change streams, snapshot queries), deprecations, and fixes across versions 8.1.2 to 8.3.0.
src/Schema/Grammar.php Added 'Invisible' modifier to $modifiers and a new method modifyInvisible for SQL syntax generation for invisible columns.
tests/Schema/BlueprintTest.php Added test_invisible_columns method, updated test_create_with_row_deletion_policy, and added test_createChangeStream_for_with_options for enhanced testing coverage.

Possibly related PRs

  • feat: add change stream support #230: The main PR includes support for change streams, which is directly related to the changes introduced in this PR that also adds change stream support in the Laravel Spanner package.

Suggested reviewers

  • Uyan712

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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 mentioned this pull request Nov 6, 2024
15 tasks
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: 0

🧹 Outside diff range and nitpick comments (4)
CHANGELOG.md (2)

3-3: Enhance the changelog entry for invisible columns.

The entry for invisible columns support could be more descriptive to help users understand the feature and its implications. Consider expanding it to:

-add support for invisible columns (#240)
+add support for invisible columns in table schemas (#240)
+  - Allows creating columns that are hidden from SELECT * queries
+  - Can be explicitly selected by column name
+  - Useful for gradual schema changes and A/B testing

Line range hint 1-9: Consider categorizing changes in version 8.3.0.

To improve readability and help users understand the impact of changes, consider organizing the entries into categories:

# v8.3.0 (2024-09-02)

-add support for invisible columns (#240)
-add support for change streams using Blueprint (#230)
-add support for snapshot queries (#215)
-deprecate Connection::getDatabaseContext() and move logic to UseMutations::getMutationExecutor() (#227)
-add support for `Query\Builder::whereNotInUnnest(...)` (#225)
-`Query\Builder::whereIn` will now wrap values in `UNNEST` if the number of values exceeds the limit (950). (#226)
-Commit options can now be set through config or through `Connection::setCommitOptions(...)` (#229)

+Added:
+- Support for invisible columns in table schemas (#240)
+- Support for change streams using Blueprint (#230)
+- Support for snapshot queries (#215)
+- Support for `Query\Builder::whereNotInUnnest(...)` (#225)
+
+Changed:
+- `Query\Builder::whereIn` will now wrap values in `UNNEST` if the number of values exceeds the limit (950) (#226)
+- Commit options can now be set through config or through `Connection::setCommitOptions(...)` (#229)
+
+Deprecated:
+- `Connection::getDatabaseContext()` - use `UseMutations::getMutationExecutor()` instead (#227)
src/Schema/Grammar.php (1)

740-752: Consider making the invisible column check more explicit.

The implementation is correct, but could be more explicit about the boolean nature of the invisible property.

Consider this alternative implementation for better type safety and readability:

     protected function modifyInvisible(Blueprint $blueprint, Fluent $column)
     {
-        return $column->invisible !== null
+        return $column->invisible === true
             ? ' hidden'
             : null;
     }
tests/Schema/BlueprintTest.php (1)

258-280: LGTM! Consider adding more test cases.

The test effectively verifies the basic functionality of invisible columns. The implementation follows good testing practices with clear setup, execution, and assertions.

Consider adding these additional test cases to improve coverage:

  1. Verify behavior when explicitly selecting the invisible column
  2. Test multiple invisible columns
  3. Test updating invisible column values
  4. Test behavior with NULL values in invisible columns

Example addition:

 $row = $conn->table($tableName)->first();
 $this->assertArrayHasKey('id', $row);
 $this->assertArrayNotHasKey('name', $row);
+
+// Test explicit selection of invisible column
+$row = $conn->table($tableName)->select(['id', 'name'])->first();
+$this->assertArrayHasKey('name', $row);
+$this->assertSame('test', $row['name']);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 04fb5bc and 7ea5fa1.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • src/Schema/Grammar.php (3 hunks)
  • tests/Schema/BlueprintTest.php (1 hunks)
🔇 Additional comments (1)
src/Schema/Grammar.php (1)

42-42: LGTM! The modifier list is updated correctly.

The addition of 'Invisible' to the $modifiers array is consistent with the new invisible column feature.

@taka-oyama taka-oyama force-pushed the feature/invisible-columns branch from 40a0dfe to fbe37a9 Compare November 7, 2024 04:54
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: 0

🧹 Outside diff range and nitpick comments (3)
CHANGELOG.md (1)

Line range hint 3-9: Consider adding usage details for the invisible columns feature.

While the changelog entry correctly documents the addition of invisible columns support, it would be helpful to include:

  • Basic usage example of invisible columns
  • Common use cases (e.g., TOKENLIST)
  • Any configuration requirements

Would you like me to help draft detailed documentation for the invisible columns feature?

src/Schema/Grammar.php (1)

737-739: Consider adding implementation note in PHPDoc.

Add a note explaining that this method translates Laravel's 'invisible' modifier to Google Cloud Spanner's 'hidden' keyword for better maintainability.

 /**
  * Get the SQL for an invisible column modifier.
+ * Note: This translates Laravel's 'invisible' modifier to Google Cloud Spanner's 'hidden' keyword.
  *
tests/Schema/BlueprintTest.php (1)

258-280: LGTM! Well-structured test for invisible columns feature.

The test comprehensively covers the invisible columns functionality:

  1. SQL generation for table creation
  2. Data insertion behavior
  3. Data retrieval verification

Consider adding these additional test cases to make it more robust:

  1. Test multiple invisible columns
  2. Test making visible columns invisible after table creation
  3. Test making invisible columns visible
 public function test_invisible_columns(): void
 {
     $conn = $this->getDefaultConnection();
     $grammar = new Grammar();
     $tableName = $this->generateTableName('Invisible');

     $blueprint = new Blueprint($tableName, function (Blueprint $table) {
         $table->create();
         $table->integer('id')->primary();
         $table->string('name')->nullable()->invisible();
+        // Add more test cases
+        $table->string('description')->invisible();
     });

     $this->assertSame([
-        "create table `{$tableName}` (`id` int64 not null, `name` string(255) hidden) primary key (`id`)",
+        "create table `{$tableName}` (`id` int64 not null, `name` string(255) hidden, `description` string(255) hidden) primary key (`id`)",
     ], $blueprint->toSql($conn, $grammar));

     $blueprint->build($conn, $grammar);

-    $conn->table($tableName)->insert(['id' => 1, 'name' => 'test']);
+    $conn->table($tableName)->insert(['id' => 1, 'name' => 'test', 'description' => 'test desc']);
     $row = $conn->table($tableName)->first();
     $this->assertArrayHasKey('id', $row);
     $this->assertArrayNotHasKey('name', $row);
+    $this->assertArrayNotHasKey('description', $row);
+
+    // Test altering column visibility
+    $blueprint = new Blueprint($tableName, function (Blueprint $table) {
+        $table->string('name')->invisible(false)->change();
+    });
+    $blueprint->build($conn, $grammar);
+    
+    $row = $conn->table($tableName)->first();
+    $this->assertArrayHasKey('name', $row);
+    $this->assertArrayNotHasKey('description', $row);
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2dcdde6 and fbe37a9.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • src/Schema/Grammar.php (3 hunks)
  • tests/Schema/BlueprintTest.php (1 hunks)
🔇 Additional comments (4)
CHANGELOG.md (1)

Line range hint 1-999: LGTM! The changelog maintains excellent structure and clarity.

The changelog follows best practices with:

  • Consistent semantic versioning
  • Clear PR references
  • Proper categorization of changes
  • Explicit marking of breaking changes
src/Schema/Grammar.php (3)

42-42: LGTM! Modifier array updated correctly.

The addition of 'Invisible' to the modifiers array is consistent with the existing pattern and correctly enables the invisible column support.


737-749: LGTM! Invisible column modifier implemented correctly.

The implementation correctly translates Laravel's 'invisible' modifier to Google Cloud Spanner's 'hidden' keyword.


737-749: Verify test coverage for invisible columns.

The implementation looks good. Let's verify the test coverage:

✅ Verification successful

Test coverage for invisible columns is confirmed

The implementation is properly tested in tests/Schema/BlueprintTest.php with a dedicated test case that verifies the invisible column functionality, including:

  • Table creation with an invisible column
  • Proper column definition using the invisible() modifier
  • Integration with other column modifiers (nullable)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are tests for invisible columns
rg -l "test.*invisible.*column" "tests/"

Length of output: 71


Script:

#!/bin/bash
# Check the actual test implementation for invisible columns
rg -A 10 "test.*invisible.*column" "tests/Schema/BlueprintTest.php"

Length of output: 492

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: 0

🧹 Outside diff range and nitpick comments (1)
src/Schema/Grammar.php (1)

736-748: LGTM! Implementation of invisible column modifier.

The implementation is clean and follows Laravel's modifier method patterns. The SQL syntax generation is correct with proper spacing.

Consider enhancing the PHPDoc with:

  1. A brief description of invisible columns' purpose
  2. A link to Cloud Spanner's documentation about invisible columns
  3. Example usage
 /**
  * Get the SQL for an invisible column modifier.
+ *
+ * Invisible columns are hidden from SELECT * queries and must be explicitly
+ * specified in the SELECT clause to be retrieved.
+ *
+ * @see https://cloud.google.com/spanner/docs/invisible-columns
  *
  * @param Blueprint $blueprint
  * @param ColumnDefinition&object{ invisible: bool } $column
  * @return string|null
+ *
+ * @example
+ * $table->string('token')->invisible();
  */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fbe37a9 and 06a49aa.

📒 Files selected for processing (1)
  • src/Schema/Grammar.php (2 hunks)
🔇 Additional comments (2)
src/Schema/Grammar.php (2)

41-41: LGTM! Addition of 'Invisible' modifier.

The addition of 'Invisible' to the modifiers array is consistent with Laravel's schema grammar pattern and enables the invisible column feature.


736-748: Verify test coverage and documentation.

Let's ensure the invisible column feature is properly tested and documented.

✅ Verification successful

Invisible column feature is properly implemented and tested

The verification shows:

  • Test coverage exists in tests/Schema/BlueprintTest.php with a dedicated test case test_invisible_columns()
  • The test verifies the correct SQL generation including the hidden keyword
  • Implementation is consistent across Grammar.php and ColumnDefinition.php

While there's no dedicated documentation found, this is a low-level database feature that is typically documented in the database's own documentation rather than requiring extensive application-level documentation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for test coverage of invisible columns
echo "Checking for test coverage..."
rg -l "invisible|hidden" "tests/"

# Check for documentation updates
echo -e "\nChecking for documentation updates..."
rg -l "invisible|hidden" "docs/"

Length of output: 303


Script:

#!/bin/bash
# Let's check the actual test implementation
echo "Checking test implementation for invisible columns..."
rg "invisible|hidden" "tests/Schema/BlueprintTest.php" -B 2 -A 2

# Let's also check if there are any schema-related documentation files in other locations
echo -e "\nChecking for schema documentation in other locations..."
fd -t f -e md . | rg -l "schema|column"

# Let's verify the Blueprint class implementation
echo -e "\nChecking Blueprint implementation..."
rg "invisible" "src/" -B 2 -A 2

Length of output: 1918

Copy link
Contributor

@halnique halnique left a comment

Choose a reason for hiding this comment

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

LGTM

@taka-oyama taka-oyama merged commit e60ce6b into master Nov 8, 2024
1 check passed
@taka-oyama taka-oyama deleted the feature/invisible-columns branch November 8, 2024 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request waiting for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants